Package io.servicetalk.http.api
Class HttpSerializationProviders
- java.lang.Object
-
- io.servicetalk.http.api.HttpSerializationProviders
-
public final class HttpSerializationProviders extends java.lang.Object
A factory to createHttpSerializationProvider
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedDeserializer()
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedDeserializer(java.nio.charset.Charset charset)
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedDeserializer(java.nio.charset.Charset charset, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedSerializer()
Creates anHttpSerializer
that can serialize a key-valuesMap
s withStandardCharsets.UTF_8
Charset
to urlencoded forms.static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedSerializer(java.nio.charset.Charset charset)
Creates anHttpSerializer
that can serialize key-valuesMap
s with the specifiedCharset
to to urlencoded forms.static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>
formUrlEncodedSerializer(java.nio.charset.Charset charset, java.util.function.Consumer<HttpHeaders> addContentType)
Creates anHttpSerializer
that can serialize a key-valuesMap
s with the specifiedCharset
to urlencoded forms.static HttpSerializationProvider
jsonSerializer(SerializationProvider serializationProvider)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from JSON using the passedSerializationProvider
.static HttpSerializationProvider
jsonSerializer(Serializer serializer)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from JSON using the passedSerializer
.static HttpSerializationProvider
serializationProvider(SerializationProvider serializationProvider, java.util.function.Consumer<HttpHeaders> addContentType, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from the desired content-type using the passedSerializationProvider
.static HttpSerializationProvider
serializationProvider(Serializer serializer, java.util.function.Consumer<HttpHeaders> addContentType, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from the desired content-type using the passedSerializer
.static HttpDeserializer<java.lang.String>
textDeserializer()
static HttpDeserializer<java.lang.String>
textDeserializer(java.nio.charset.Charset charset)
static HttpDeserializer<java.lang.String>
textDeserializer(java.nio.charset.Charset charset, java.util.function.Predicate<HttpHeaders> checkContentType)
static HttpSerializer<java.lang.String>
textSerializer()
static HttpSerializer<java.lang.String>
textSerializer(java.nio.charset.Charset charset)
static HttpSerializer<java.lang.String>
textSerializer(java.nio.charset.Charset charset, java.util.function.Consumer<HttpHeaders> addContentType)
-
-
-
Method Detail
-
formUrlEncodedSerializer
public static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedSerializer()
Creates anHttpSerializer
that can serialize a key-valuesMap
s withStandardCharsets.UTF_8
Charset
to urlencoded forms.- Returns:
HttpSerializer
that could serialize key-valueMap
.- See Also:
- x-www-form-urlencoded specification
-
formUrlEncodedSerializer
public static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedSerializer(java.nio.charset.Charset charset)
Creates anHttpSerializer
that can serialize key-valuesMap
s with the specifiedCharset
to to urlencoded forms.- Parameters:
charset
-Charset
for the key-valueMap
that will be serialized.- Returns:
HttpSerializer
that could serialize from key-valueMap
.- See Also:
- x-www-form-urlencoded specification
-
formUrlEncodedSerializer
public static HttpSerializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedSerializer(java.nio.charset.Charset charset, java.util.function.Consumer<HttpHeaders> addContentType)
Creates anHttpSerializer
that can serialize a key-valuesMap
s with the specifiedCharset
to urlencoded forms.- Parameters:
charset
-Charset
for the key-valueMap
that will be serialized.addContentType
- AConsumer
that adds relevant headers to the passedHttpHeaders
matching the serialized payload. Typically, this involves adding aHttpHeaderNames.CONTENT_TYPE
header.- Returns:
HttpSerializer
that could serialize from key-valueMap
.- See Also:
- x-www-form-urlencoded specification
-
formUrlEncodedDeserializer
public static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedDeserializer()
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.- Returns:
HttpDeserializer
that could deserialize a key-valuesMap
.- See Also:
- x-www-form-urlencoded specification
-
formUrlEncodedDeserializer
public static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedDeserializer(java.nio.charset.Charset charset)
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.- Parameters:
charset
-Charset
for the key-valueMap
that will be deserialized. deserialized payload. If the validation fails, then deserialization will fail withSerializationException
- Returns:
HttpDeserializer
that could deserialize a key-valueMap
.- See Also:
- x-www-form-urlencoded specification
-
formUrlEncodedDeserializer
public static HttpDeserializer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>> formUrlEncodedDeserializer(java.nio.charset.Charset charset, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates anHttpDeserializer
that can deserialize key-valuesMap
s withStandardCharsets.UTF_8
from urlencoded forms.- Parameters:
charset
-Charset
for the key-valueMap
that will be deserialized.checkContentType
- Checks theHttpHeaders
to see if a compatible encoding is found. deserialized payload. If the validation fails, then deserialization will fail withSerializationException
- Returns:
HttpDeserializer
that could deserialize a key-valueMap
.- See Also:
- x-www-form-urlencoded specification
-
textSerializer
public static HttpSerializer<java.lang.String> textSerializer()
- Returns:
HttpSerializer
that could serializeString
.
-
textSerializer
public static HttpSerializer<java.lang.String> textSerializer(java.nio.charset.Charset charset)
- Parameters:
charset
-Charset
for theString
that will be serialized.- Returns:
HttpSerializer
that could serialize fromString
.
-
textSerializer
public static HttpSerializer<java.lang.String> textSerializer(java.nio.charset.Charset charset, java.util.function.Consumer<HttpHeaders> addContentType)
- Parameters:
charset
-Charset
for theString
that will be serialized.addContentType
- AConsumer
that adds relevant headers to the passedHttpHeaders
matching the serialized payload. Typically, this involves adding aHttpHeaderNames.CONTENT_TYPE
header.- Returns:
HttpSerializer
that could serialize fromString
.
-
textDeserializer
public static HttpDeserializer<java.lang.String> textDeserializer()
- Returns:
HttpDeserializer
that could deserializeString
.
-
textDeserializer
public static HttpDeserializer<java.lang.String> textDeserializer(java.nio.charset.Charset charset)
- Parameters:
charset
-Charset
for theString
that will be deserialized.- Returns:
HttpDeserializer
that could deserializeString
.
-
textDeserializer
public static HttpDeserializer<java.lang.String> textDeserializer(java.nio.charset.Charset charset, java.util.function.Predicate<HttpHeaders> checkContentType)
- Parameters:
charset
-Charset
for theString
that will be deserialized.checkContentType
- APredicate
that validates the passedHttpHeaders
as expected for the deserialized payload. If the validation fails, then deserialization will fail withSerializationException
- Returns:
HttpDeserializer
that could deserializeString
.
-
jsonSerializer
public static HttpSerializationProvider jsonSerializer(Serializer serializer)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from JSON using the passedSerializer
. For serialization, the returnedHttpSerializationProvider
adds aHttpHeaderNames.CONTENT_TYPE
header with valueHttpHeaderValues.APPLICATION_JSON
. For deserialization, it expects aHttpHeaderNames.CONTENT_TYPE
header with valueHttpHeaderValues.APPLICATION_JSON
. If the expected header is not present, then deserialization will fail withSerializationException
.- Parameters:
serializer
-Serializer
that has the capability of serializing/deserializing to/from JSON.- Returns:
HttpSerializationProvider
that has the capability of serializing/deserializing to/from JSON.
-
jsonSerializer
public static HttpSerializationProvider jsonSerializer(SerializationProvider serializationProvider)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from JSON using the passedSerializationProvider
. For serialization, the returnedHttpSerializationProvider
adds aHttpHeaderNames.CONTENT_TYPE
header with valueHttpHeaderValues.APPLICATION_JSON
. For deserialization, it expects aHttpHeaderNames.CONTENT_TYPE
header with valueHttpHeaderValues.APPLICATION_JSON
. If the expected header is not present, then deserialization will fail withSerializationException
.- Parameters:
serializationProvider
-SerializationProvider
that has the capability of serializing/deserializing to/from JSON.- Returns:
HttpSerializationProvider
that has the capability of serializing/deserializing to/from JSON.
-
serializationProvider
public static HttpSerializationProvider serializationProvider(Serializer serializer, java.util.function.Consumer<HttpHeaders> addContentType, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from the desired content-type using the passedSerializer
.For serialization, the returned
HttpSerializationProvider
would updateHttpHeaders
appropriately to indicate the content-type using the passedaddContentType
.For deserialization, it would validate headers as specified by the passed
checkContentType predicate
. If the validation fails, then deserialization will fail withSerializationException
.- Parameters:
serializer
-Serializer
that has the capability of serializing/deserializing to/from a desired content-type.addContentType
- AConsumer
that adds relevant headers to the passedHttpHeaders
matching the serialized payload. Typically, this involves adding aHttpHeaderNames.CONTENT_TYPE
header.checkContentType
- APredicate
that validates the passedHttpHeaders
as expected for the deserialized payload. If the validation fails, then deserialization will fail withSerializationException
- Returns:
HttpSerializationProvider
that has the capability of serializing/deserializing to/from a desired content-type.
-
serializationProvider
public static HttpSerializationProvider serializationProvider(SerializationProvider serializationProvider, java.util.function.Consumer<HttpHeaders> addContentType, java.util.function.Predicate<HttpHeaders> checkContentType)
Creates a newHttpSerializationProvider
that could serialize/deserialize to/from the desired content-type using the passedSerializationProvider
.For serialization, the returned
HttpSerializationProvider
would updateHttpHeaders
appropriately to indicate the content-type using the passedaddContentType
.For deserialization, it would validate headers as specified by the passed
checkContentType predicate
. If the validation fails, then deserialization will fail withSerializationException
.- Parameters:
serializationProvider
-SerializationProvider
that has the capability of serializing/deserializing to/from a desired content-type.addContentType
- AConsumer
that adds relevant headers to the passedHttpHeaders
matching the serialized payload. Typically, this involves adding aHttpHeaderNames.CONTENT_TYPE
header.checkContentType
- APredicate
that validates the passedHttpHeaders
as expected for the deserialized payload. If the validation fails, then deserialization will fail withSerializationException
.- Returns:
HttpSerializationProvider
that has the capability of serializing/deserializing to/from a desired content-type.
-
-