Class KotlinSerializationBinaryEncoder<T extends kotlinx.serialization.BinaryFormat>

java.lang.Object
org.springframework.http.codec.KotlinSerializationSupport<T>
org.springframework.http.codec.KotlinSerializationBinaryEncoder<T>
Type Parameters:
T - the type of BinaryFormat
All Implemented Interfaces:
org.springframework.core.codec.Encoder<Object>
Direct Known Subclasses:
KotlinSerializationCborEncoder, KotlinSerializationProtobufEncoder

public abstract class KotlinSerializationBinaryEncoder<T extends kotlinx.serialization.BinaryFormat> extends KotlinSerializationSupport<T> implements org.springframework.core.codec.Encoder<Object>
Abstract base class for Encoder implementations that defer to Kotlin binary serializers.

As of Spring Framework 7.0, by default it only encodes types annotated with @Serializable at type or generics level since it allows combined usage with other general purpose encoders without conflicts. Alternative constructors with a Predicate<ResolvableType> parameter can be used to customize this behavior.

Since:
6.0
Author:
Sebastien Deleuze, Iain Henderson, Arjen Poutsma
  • Constructor Details

    • KotlinSerializationBinaryEncoder

      protected KotlinSerializationBinaryEncoder(T format, org.springframework.util.MimeType... supportedMimeTypes)
      Creates a new instance with the given format and supported mime types which only encodes types annotated with @Serializable at type or generics level.
    • KotlinSerializationBinaryEncoder

      protected KotlinSerializationBinaryEncoder(T format, Predicate<org.springframework.core.ResolvableType> typePredicate, org.springframework.util.MimeType... supportedMimeTypes)
      Creates a new instance with the given format and supported mime types which only encodes types for which the specified predicate returns true.
      Since:
      7.0
  • Method Details

    • canEncode

      public boolean canEncode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType)
      Specified by:
      canEncode in interface org.springframework.core.codec.Encoder<T extends kotlinx.serialization.BinaryFormat>
    • getEncodableMimeTypes

      public List<org.springframework.util.MimeType> getEncodableMimeTypes()
      Specified by:
      getEncodableMimeTypes in interface org.springframework.core.codec.Encoder<T extends kotlinx.serialization.BinaryFormat>
    • getEncodableMimeTypes

      public List<org.springframework.util.MimeType> getEncodableMimeTypes(org.springframework.core.ResolvableType elementType)
      Specified by:
      getEncodableMimeTypes in interface org.springframework.core.codec.Encoder<T extends kotlinx.serialization.BinaryFormat>
    • encode

      public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> encode(Publisher<?> inputStream, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)
      Specified by:
      encode in interface org.springframework.core.codec.Encoder<T extends kotlinx.serialization.BinaryFormat>
    • encodeValue

      public org.springframework.core.io.buffer.DataBuffer encodeValue(Object value, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType valueType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)
      Specified by:
      encodeValue in interface org.springframework.core.codec.Encoder<T extends kotlinx.serialization.BinaryFormat>