Class KotlinSerializationJsonDecoder
java.lang.Object
org.springframework.http.codec.KotlinSerializationSupport<kotlinx.serialization.json.Json>
org.springframework.http.codec.KotlinSerializationStringDecoder<kotlinx.serialization.json.Json>
org.springframework.http.codec.json.KotlinSerializationJsonDecoder
public class KotlinSerializationJsonDecoder
extends KotlinSerializationStringDecoder<kotlinx.serialization.json.Json>
Decode a byte stream into JSON and convert to Object's with
kotlinx.serialization.
It supports
application/json and application/*+json with
various character sets, UTF-8 being the default.
As of Spring Framework 7.0, by default it only decodes types annotated with
@Serializable at type or generics
level since it allows combined usage with other general purpose JSON decoders
like JacksonJsonDecoder without conflicts.
Alternative constructors with a Predicate<ResolvableType>
parameter can be used to customize this behavior. For example,
new KotlinSerializationJsonDecoder(type -> true) will decode all types
supported by Kotlin Serialization, including unannotated Kotlin enumerations,
numbers, characters, booleans and strings.
Decoding streams is not supported yet, see kotlinx.serialization/issues/1073 related issue.
- Since:
- 5.3
- Author:
- Sebastien Deleuze, Iain Henderson
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new decoder usingJson.Defaultinstance which only decodes types annotated with@Serializableat type or generics level.KotlinSerializationJsonDecoder(Predicate<ResolvableType> typePredicate) Construct a new decoder usingJson.Defaultinstance which only decodes types for which the specified predicate returnstrue.KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json) Construct a new decoder using the providedJsoninstance which only decodes types annotated with@Serializableat type or generics level.KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json, Predicate<ResolvableType> typePredicate) Construct a new decoder using the providedJsoninstance which only decodes types for which the specified predicate returnstrue. -
Method Summary
Methods inherited from class KotlinSerializationStringDecoder
canDecode, decode, decodeToMono, getDecodableMimeTypes, getDecodableMimeTypes, getMaxInMemorySize, setMaxInMemorySizeMethods inherited from class KotlinSerializationSupport
canSerialize, format, serializer, supportedMimeTypes
-
Constructor Details
-
KotlinSerializationJsonDecoder
public KotlinSerializationJsonDecoder()Construct a new decoder usingJson.Defaultinstance which only decodes types annotated with@Serializableat type or generics level. -
KotlinSerializationJsonDecoder
Construct a new decoder usingJson.Defaultinstance which only decodes types for which the specified predicate returnstrue.- Since:
- 7.0
-
KotlinSerializationJsonDecoder
public KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json) Construct a new decoder using the providedJsoninstance which only decodes types annotated with@Serializableat type or generics level. -
KotlinSerializationJsonDecoder
public KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json, Predicate<ResolvableType> typePredicate) Construct a new decoder using the providedJsoninstance which only decodes types for which the specified predicate returnstrue.- Since:
- 7.0
-