public final class HttpSerializers
extends Object
HttpSerializerDeserializer and HttpStreamingSerializerDeserializer.| Modifier and Type | Method and Description |
|---|---|
static HttpStreamingSerializerDeserializer<String> |
appSerializerAsciiFixLen()
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using fixed int length delimited framing. |
static HttpStreamingSerializerDeserializer<String> |
appSerializerAsciiVarLen()
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using variable int length delimited framing. |
static HttpStreamingSerializerDeserializer<String> |
appSerializerFixLen(Charset charset)
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing. |
static HttpStreamingSerializerDeserializer<String> |
appSerializerUtf8FixLen()
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using fixed int length delimited framing. |
static HttpStreamingSerializerDeserializer<String> |
appSerializerUtf8VarLen()
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using variable int length delimited framing. |
static HttpStreamingSerializerDeserializer<String> |
appSerializerVarLen(Charset charset)
Creates a
HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing. |
static HttpStreamingSerializer<byte[]> |
bytesStreamingSerializer(Consumer<HttpHeaders> headersSerializeConsumer)
Create a
HttpStreamingSerializer that serializes byte[]. |
static HttpSerializerDeserializer<Map<String,List<String>>> |
formUrlEncodedSerializer()
Get a
HttpSerializerDeserializer that can serialize a key-values Maps
with StandardCharsets.UTF_8 Charset to urlencoded forms. |
static HttpSerializerDeserializer<Map<String,List<String>>> |
formUrlEncodedSerializer(Charset charset)
Get a
HttpSerializerDeserializer that can serialize a key-values Maps
with a Charset to urlencoded forms. |
static <T> HttpSerializerDeserializer<T> |
jsonSerializer(SerializerDeserializer<T> serializer)
Creates an
HttpSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON. |
static <T> HttpStreamingSerializerDeserializer<T> |
jsonStreamingSerializer(StreamingSerializerDeserializer<T> serializer)
Creates an
HttpStreamingSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON. |
static <T> HttpSerializerDeserializer<T> |
serializer(SerializerDeserializer<T> serializer,
Consumer<HttpHeaders> headersSerializeConsumer,
Predicate<HttpHeaders> headersDeserializePredicate)
Creates an
HttpSerializerDeserializer that uses SerializerDeserializer for serialization. |
static <T> HttpStreamingSerializer<T> |
streamingSerializer(Serializer<T> serializer,
ToIntFunction<T> bytesEstimator,
Consumer<HttpHeaders> headersSerializeConsumer)
Create a
HttpStreamingSerializer that uses a Serializer for serialization. |
static <T> HttpStreamingSerializerDeserializer<T> |
streamingSerializer(StreamingSerializerDeserializer<T> serializer,
Consumer<HttpHeaders> headersSerializeConsumer,
Predicate<HttpHeaders> headersDeserializePredicate)
Creates an
HttpStreamingSerializerDeserializer that uses StreamingSerializerDeserializer for
serialization. |
static HttpStreamingSerializer<String> |
stringStreamingSerializer(Charset charset,
Consumer<HttpHeaders> headersSerializeConsumer)
Create a
HttpStreamingSerializer that serializes String. |
static HttpSerializerDeserializer<String> |
textSerializer(Charset charset)
|
static HttpSerializerDeserializer<String> |
textSerializerAscii()
|
static HttpSerializerDeserializer<String> |
textSerializerUtf8()
|
public static HttpSerializerDeserializer<Map<String,List<String>>> formUrlEncodedSerializer()
HttpSerializerDeserializer that can serialize a key-values Maps
with StandardCharsets.UTF_8 Charset to urlencoded forms.HttpSerializerDeserializer that could serialize key-value Map.public static HttpSerializerDeserializer<Map<String,List<String>>> formUrlEncodedSerializer(Charset charset)
HttpSerializerDeserializer that can serialize a key-values Maps
with a Charset to urlencoded forms.charset - The Charset to use for value encoding.HttpSerializerDeserializer that could serialize key-value Map.public static HttpSerializerDeserializer<String> textSerializerUtf8()
HttpSerializerDeserializer that can serialize Strings.public static HttpSerializerDeserializer<String> textSerializerAscii()
HttpSerializerDeserializer that can serialize Strings.public static HttpSerializerDeserializer<String> textSerializer(Charset charset)
charset - The Charset to use for encoding.HttpSerializerDeserializer that can serialize Strings.public static HttpStreamingSerializerDeserializer<String> appSerializerUtf8FixLen()
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using fixed int length delimited framing. The framing is required
so the same String objects can be deserialized by the peer, otherwise the boundaries aren't known. If
the desire is to serialize raw data contained in the String, see
stringStreamingSerializer(Charset, Consumer). The HttpHeaderNames.CONTENT_TYPE value prefix is
.HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using fixed int length delimited framing.FixedLengthStreamingSerializerpublic static HttpStreamingSerializerDeserializer<String> appSerializerUtf8VarLen()
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using variable int length delimited framing. The framing is
required so the same String objects can be deserialized by the peer, otherwise the boundaries aren't
known. If the desire is to serialize raw data contained in the String, see
stringStreamingSerializer(Charset, Consumer). The HttpHeaderNames.CONTENT_TYPE value prefix is
.HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.UTF_8 encoding using variable int length delimited framing.VarIntLengthStreamingSerializerpublic static HttpStreamingSerializerDeserializer<String> appSerializerAsciiFixLen()
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using fixed int length delimited framing. The framing is
required so the same String objects can be deserialized by the peer, otherwise the boundaries aren't
known. If the desire is to serialize raw data contained in the String, see
stringStreamingSerializer(Charset, Consumer). The HttpHeaderNames.CONTENT_TYPE value prefix is
.HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using fixed int length delimited framing.FixedLengthStreamingSerializerpublic static HttpStreamingSerializerDeserializer<String> appSerializerAsciiVarLen()
HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using variable int length delimited framing. The framing is
required so the same String objects can be deserialized by the peer, otherwise the boundaries aren't
known. If the desire is to serialize raw data contained in the String, see
stringStreamingSerializer(Charset, Consumer). The HttpHeaderNames.CONTENT_TYPE value prefix is
.HttpStreamingSerializerDeserializer that serializes Strings with
StandardCharsets.US_ASCII encoding using variable int length delimited framing.VarIntLengthStreamingSerializerpublic static HttpStreamingSerializerDeserializer<String> appSerializerFixLen(Charset charset)
HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing. The framing is required so the same
String objects can be deserialized by the peer, otherwise the boundaries aren't known. If the desire is
to serialize raw data contained in the String, see stringStreamingSerializer(Charset, Consumer).
The HttpHeaderNames.CONTENT_TYPE value prefix is .charset - The character encoding to use for serialization.HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing.FixedLengthStreamingSerializerpublic static HttpStreamingSerializerDeserializer<String> appSerializerVarLen(Charset charset)
HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing. The framing is required so the same
String objects can be deserialized by the peer, otherwise the boundaries aren't known. If the desire is
to serialize raw data contained in the String, see stringStreamingSerializer(Charset, Consumer).
The HttpHeaderNames.CONTENT_TYPE value prefix is .charset - The character encoding to use for serialization.HttpStreamingSerializerDeserializer that serializes Strings with
charset encoding using fixed int length delimited framing.VarIntLengthStreamingSerializerpublic static HttpStreamingSerializer<String> stringStreamingSerializer(Charset charset, Consumer<HttpHeaders> headersSerializeConsumer)
HttpStreamingSerializer that serializes String. This method is useful if the payload
body is provided in String and the HttpHeaderNames.CONTENT_TYPE is known a-priori
(e.g. streaming raw json data from a stream of Strings). Deserialization should be done using
the a-priori knowledge to use a compatible HttpStreamingDeserializer. To elaborate why a-priori knowledge
of how content is consumed/deserialized is required consider the following caveats of this method:
String
objects. For example, if ("foo", "bar") is serialized the deserialization may not
be able to reliably return "foo" and "bar". If the result of the serialization is sent as a
stream of bytes (e.g. TCP over a network) the deserialization will produce Strings as read from the
stream. For example, if the deserialization is done in a streaming fashion this is a valid result:
("f", "o", "oba", "r"). If the receiver always aggregates data before deserialization they will
reliably get "foobar".String encoding represents a single character with multiple bytes
(e.g. StandardCharsets.UTF_8) the deserialization may encounter errors if the results are processed
as a stream of bytes (see description above).appSerializerFixLen(Charset) and appSerializerVarLen(Charset) introduce a framing and
therefore are not subject to the above caveats.charset - The character encoding to use for serialization.headersSerializeConsumer - Sets the headers to indicate the appropriate encoding and content type.HttpStreamingSerializer that uses a Serializer for serialization.public static HttpStreamingSerializer<byte[]> bytesStreamingSerializer(Consumer<HttpHeaders> headersSerializeConsumer)
HttpStreamingSerializer that serializes byte[]. This method is useful if the payload
body is provided in byte[] and the HttpHeaderNames.CONTENT_TYPE is known a-priori
(e.g. streaming raw json data from a stream of byte[]s). Deserialization should be done using
the a-priori knowledge to use a compatible HttpStreamingDeserializer.headersSerializeConsumer - Sets the headers to indicate the appropriate encoding and content type.HttpStreamingSerializer that uses a Serializer for serialization.public static <T> HttpSerializerDeserializer<T> jsonSerializer(SerializerDeserializer<T> serializer)
HttpSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON.T - Type of object to serialize.serializer - Used to serialize each T.HttpSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON.public static <T> HttpStreamingSerializerDeserializer<T> jsonStreamingSerializer(StreamingSerializerDeserializer<T> serializer)
HttpStreamingSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON.T - Type of object to serialize.serializer - Used to serialize each T.HttpStreamingSerializerDeserializer that targets HttpHeaderValues.APPLICATION_JSON.public static <T> HttpSerializerDeserializer<T> serializer(SerializerDeserializer<T> serializer, Consumer<HttpHeaders> headersSerializeConsumer, Predicate<HttpHeaders> headersDeserializePredicate)
HttpSerializerDeserializer that uses SerializerDeserializer for serialization.T - Type of object to serialize.serializer - Used to serialize each T.headersSerializeConsumer - Sets the headers to indicate the appropriate encoding and content type.headersDeserializePredicate - Validates the headers are of the supported encoding and content type.HttpSerializerDeserializer that uses a SerializerDeserializer for serialization.public static <T> HttpStreamingSerializerDeserializer<T> streamingSerializer(StreamingSerializerDeserializer<T> serializer, Consumer<HttpHeaders> headersSerializeConsumer, Predicate<HttpHeaders> headersDeserializePredicate)
HttpStreamingSerializerDeserializer that uses StreamingSerializerDeserializer for
serialization.T - Type of object to serialize.serializer - Used to serialize each T.headersSerializeConsumer - Sets the headers to indicate the appropriate encoding and content type.headersDeserializePredicate - Validates the headers are of the supported encoding and content type.HttpStreamingSerializerDeserializer that uses a StreamingSerializerDeserializer for
serialization.public static <T> HttpStreamingSerializer<T> streamingSerializer(Serializer<T> serializer, ToIntFunction<T> bytesEstimator, Consumer<HttpHeaders> headersSerializeConsumer)
HttpStreamingSerializer that uses a Serializer for serialization. This method is useful
if the payload body is provided in non-Buffer type and the HttpHeaderNames.CONTENT_TYPE is known
a-priori (e.g. streaming raw json data from a stream of Strings). Deserialization should be done using
the a-priori knowledge to use a compatible HttpStreamingDeserializer.T - Type of object to serialize.serializer - Used to serialize each T chunk.bytesEstimator - Provides an estimate of how many bytes to allocate for each Buffer to serialize to.headersSerializeConsumer - Sets the headers to indicate the appropriate encoding and content type.HttpStreamingSerializer that uses a Serializer for serialization.