Class KotlinSerializationJsonHttpMessageConverter

All Implemented Interfaces:
HttpMessageConverter<Object>, SmartHttpMessageConverter<Object>

public class KotlinSerializationJsonHttpMessageConverter extends KotlinSerializationStringHttpMessageConverter<kotlinx.serialization.json.Json>
Implementation of HttpMessageConverter that can read and write JSON using 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 types annotated with @Serializable at type or generics level since it allows combined usage with other general purpose JSON decoders like JacksonJsonHttpMessageConverter without conflicts.

Alternative constructors with a Predicate<ResolvableType> parameter can be used to customize this behavior. For example, new KotlinSerializationJsonHttpMessageConverter(type -> true) will decode all types supported by Kotlin Serialization, including unannotated Kotlin enumerations, numbers, characters, booleans and strings.

Since:
5.3
Author:
Andreas Ahlenstorf, Sebastien Deleuze, Juergen Hoeller, Iain Henderson
  • Constructor Details

    • KotlinSerializationJsonHttpMessageConverter

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

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

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

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