Top Description Fields Constructors Methods
org.springframework.http.converter

public abstract Class AbstractKotlinSerializationHttpMessageConverter<T extends kotlinx.serialization.SerialFormat>

extends AbstractGenericHttpMessageConverter<Object>
Class Inheritance
Known Direct Subclasses
org.springframework.http.converter.KotlinSerializationBinaryHttpMessageConverter, org.springframework.http.converter.KotlinSerializationStringHttpMessageConverter
Type Parameters
<T>
the type of SerialFormat
Imports
java.io.IOException, java.lang.reflect.Type, java.util.HashSet, .Map, .Set, kotlinx.serialization.KSerializer, kotlinx.serialization.SerialFormat, kotlinx.serialization.SerializersKt, kotlinx.serialization.descriptors.PolymorphicKind, kotlinx.serialization.descriptors.SerialDescriptor, org.springframework.core.GenericTypeResolver, org.springframework.http.HttpInputMessage, .HttpOutputMessage, .MediaType, org.springframework.lang.Nullable, org.springframework.util.ConcurrentReferenceHashMap

Abstract base class for HttpMessageConverter implementations that use Kotlin serialization.
Authors
Andreas Ahlenstorf, Sebastien Deleuze, Juergen Hoeller, Iain Henderson, Arjen Poutsma
Since
6.0

Field Summary

Modifier and TypeField and Description
private final T
private final Map<Type, kotlinx.serialization.KSerializer<Object>>

Constructor Summary

AccessConstructor and Description
protected
AbstractKotlinSerializationHttpMessageConverter(T
the format
format
,
MediaType...
the supported media types
supportedMediaTypes
)

Construct an AbstractKotlinSerializationHttpMessageConverter with multiple supported media type and format.

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(Type
the (potentially generic) type to test for readability
type
,
Class<?>
a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
contextClass
,
MediaType
the media type to read, can be null if not specified. Typically, the value of a Content-Type header.
mediaType
)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canRead.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter.
public boolean
canWrite(Type
the (potentially generic) type to test for writability (can be null if not specified)
type
,
Class<?>
the source object class to test for writability
clazz
,
MediaType
the media type to write (can be null if not specified); typically the value of an Accept header.
mediaType
)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.
private boolean
hasPolymorphism(kotlinx.serialization.descriptors.SerialDescriptor descriptor, Set<String> alreadyProcessed)

public final Object
read(Type
the (potentially generic) type of object to return. This type must have previously been passed to the canRead method of this interface, which must have returned true.
type
,
Class<?>
a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
contextClass
,
HttpInputMessage
the HTTP input message to read from
inputMessage
)

Implements org.springframework.http.converter.GenericHttpMessageConverter.read.

Read an object of the given type form the given input message, and returns it.
protected final Object
readInternal(Class<?>
the type of object to return
clazz
,
HttpInputMessage
the HTTP input message to read from
inputMessage
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object.
protected abstract Object
readInternal(kotlinx.serialization.KSerializer<Object> serializer, T format, HttpInputMessage inputMessage)

Reads the given input message with the given serializer and format.

private kotlinx.serialization.KSerializer<Object>

Returns:

a resolved serializer for the given type, or null
serializer
(Type
the type to find a serializer for
type
)

Tries to find a serializer that can marshall or unmarshall instances of the given type using kotlinx.serialization.

protected boolean
supports(Class<?>
the class to test for support
clazz
)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.
protected boolean
supportsRepeatableWrites(Object
the object t
object
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.
protected final void
writeInternal(Object
the object to write to the output message
object
,
Type
the type of object to write (may be null)
type
,
HttpOutputMessage
the HTTP output message to write to
outputMessage
)

Implements abstract org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body.
protected abstract void
writeInternal(Object object, kotlinx.serialization.KSerializer<Object> serializer, T format, HttpOutputMessage outputMessage)

Write the given object to the output message with the given serializer and format.

Inherited from org.springframework.http.converter.AbstractGenericHttpMessageConverter:
writewriteInternal

Field Detail

formatback to summary
private final T format
serializerCacheback to summary
private final Map<Type, kotlinx.serialization.KSerializer<Object>> serializerCache

Constructor Detail

AbstractKotlinSerializationHttpMessageConverterback to summary
protected AbstractKotlinSerializationHttpMessageConverter(T format, MediaType... supportedMediaTypes)

Construct an AbstractKotlinSerializationHttpMessageConverter with multiple supported media type and format.

Parameters
format:T

the format

supportedMediaTypes:MediaType[]

the supported media types

Method Detail

canReadback to summary
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canRead.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter. This method should perform the same checks as HttpMessageConverter#canRead(Class, MediaType) with additional ones related to the generic type.

Parameters
type:Type

the (potentially generic) type to test for readability

contextClass:Class<?>

a context class for the target type, for example a class in which the target type appears in a method signature (can be null)

mediaType:MediaType

the media type to read, can be null if not specified. Typically, the value of a Content-Type header.

Returns:boolean

true if readable; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.

This method should perform the same checks as HttpMessageConverter#canWrite(Class, MediaType) with additional ones related to the generic type.

Parameters
type:Type

the (potentially generic) type to test for writability (can be null if not specified)

clazz:Class<?>

the source object class to test for writability

mediaType:MediaType

the media type to write (can be null if not specified); typically the value of an Accept header.

Returns:boolean

true if writable; false otherwise

Annotations
@Override
hasPolymorphismback to summary
private boolean hasPolymorphism(kotlinx.serialization.descriptors.SerialDescriptor descriptor, Set<String> alreadyProcessed)
readback to summary
public final Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException

Implements org.springframework.http.converter.GenericHttpMessageConverter.read.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.read.

Read an object of the given type form the given input message, and returns it.

Parameters
type:Type

the (potentially generic) type of object to return. This type must have previously been passed to the canRead method of this interface, which must have returned true.

contextClass:Class<?>

a context class for the target type, for example a class in which the target type appears in a method signature (can be null)

inputMessage:HttpInputMessage

the HTTP input message to read from

Returns:Object

the converted object

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotReadableException:
in case of conversion errors
readInternalback to summary
protected final Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object. Invoked from read.

Parameters
clazz:Class<?>

the type of object to return

inputMessage:HttpInputMessage

the HTTP input message to read from

Returns:Object

the converted object

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotReadableException:
in case of conversion errors
readInternalback to summary
protected abstract Object readInternal(kotlinx.serialization.KSerializer<Object> serializer, T format, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException

Reads the given input message with the given serializer and format.

serializerback to summary
private kotlinx.serialization.KSerializer<Object> serializer(Type type)

Tries to find a serializer that can marshall or unmarshall instances of the given type using kotlinx.serialization. If no serializer can be found, null is returned.

Resolved serializers are cached and cached results are returned on successive calls.

Parameters
type:Type

the type to find a serializer for

Returns:kotlinx.serialization.KSerializer<Object>

a resolved serializer for the given type, or null

Annotations
@Nullable
supportsback to summary
protected boolean supports(Class<?> clazz)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.supports.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.

Parameters
clazz:Class<?>

the class to test for support

Returns:boolean

true if supported; false otherwise

Annotations
@Override
supportsRepeatableWritesback to summary
protected boolean supportsRepeatableWrites(Object object)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.

Default implementation returns false.

Parameters
object:Object

the object t

Returns:boolean

true if t can be written repeatedly; false otherwise

Annotations
@Override
writeInternalback to summary
protected final void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Implements abstract org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Doc from org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body. Invoked from write.

Parameters
object:Object

the object to write to the output message

type:Type

the type of object to write (may be null)

outputMessage:HttpOutputMessage

the HTTP output message to write to

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotWritableException:
in case of conversion errors
writeInternalback to summary
protected abstract void writeInternal(Object object, kotlinx.serialization.KSerializer<Object> serializer, T format, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Write the given object to the output message with the given serializer and format.