Class KotlinSerializationJsonHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
org.springframework.http.converter.AbstractSmartHttpMessageConverter<Object>
org.springframework.http.converter.AbstractKotlinSerializationHttpMessageConverter<kotlinx.serialization.json.Json>
org.springframework.http.converter.KotlinSerializationStringHttpMessageConverter<kotlinx.serialization.json.Json>
org.springframework.http.converter.json.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
-
Field Summary
Fields inherited from class AbstractHttpMessageConverter
logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new converter usingJson.Defaultinstance which only converts types annotated with@Serializableat type or generics level.KotlinSerializationJsonHttpMessageConverter(Predicate<ResolvableType> typePredicate) Construct a new converter usingJson.Defaultinstance which only converts types for which the specified predicate returnstrue.KotlinSerializationJsonHttpMessageConverter(kotlinx.serialization.json.Json json) Construct a new converter using the providedJsoninstance which only converts types annotated with@Serializableat type or generics level.KotlinSerializationJsonHttpMessageConverter(kotlinx.serialization.json.Json json, Predicate<ResolvableType> typePredicate) Construct a new converter using the providedJsoninstance which only converts types for which the specified predicate returnstrue. -
Method Summary
Methods inherited from class KotlinSerializationStringHttpMessageConverter
readInternal, writeInternalMethods inherited from class AbstractKotlinSerializationHttpMessageConverter
canRead, canWrite, getSupportedMediaTypes, read, supports, supportsRepeatableWrites, writeInternalMethods inherited from class AbstractSmartHttpMessageConverter
readInternal, write, writeInternalMethods inherited from class AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, writeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpMessageConverter
getSupportedMediaTypesMethods inherited from interface SmartHttpMessageConverter
canRead, canWrite, read, write
-
Constructor Details
-
KotlinSerializationJsonHttpMessageConverter
public KotlinSerializationJsonHttpMessageConverter()Construct a new converter usingJson.Defaultinstance which only converts types annotated with@Serializableat type or generics level. -
KotlinSerializationJsonHttpMessageConverter
Construct a new converter usingJson.Defaultinstance which only converts types for which the specified predicate returnstrue.- Since:
- 7.0
-
KotlinSerializationJsonHttpMessageConverter
public KotlinSerializationJsonHttpMessageConverter(kotlinx.serialization.json.Json json) Construct a new converter using the providedJsoninstance which only converts types annotated with@Serializableat type or generics level. -
KotlinSerializationJsonHttpMessageConverter
public KotlinSerializationJsonHttpMessageConverter(kotlinx.serialization.json.Json json, Predicate<ResolvableType> typePredicate) Construct a new converter using the providedJsoninstance which only converts types for which the specified predicate returnstrue.- Since:
- 7.0
-