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
All Implemented Interfaces:
Decoder<Object>

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 Details

    • KotlinSerializationJsonDecoder

      public KotlinSerializationJsonDecoder()
      Construct a new decoder using Json.Default instance which only decodes types annotated with @Serializable at type or generics level.
    • KotlinSerializationJsonDecoder

      public KotlinSerializationJsonDecoder(Predicate<ResolvableType> typePredicate)
      Construct a new decoder using Json.Default instance which only decodes types for which the specified predicate returns true.
      Since:
      7.0
    • KotlinSerializationJsonDecoder

      public KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json)
      Construct a new decoder using the provided Json instance which only decodes types annotated with @Serializable at type or generics level.
    • KotlinSerializationJsonDecoder

      public KotlinSerializationJsonDecoder(kotlinx.serialization.json.Json json, Predicate<ResolvableType> typePredicate)
      Construct a new decoder using the provided Json instance which only decodes types for which the specified predicate returns true.
      Since:
      7.0