Class KotlinSerializationCborEncoder

java.lang.Object
org.springframework.http.codec.KotlinSerializationSupport<kotlinx.serialization.cbor.Cbor>
org.springframework.http.codec.KotlinSerializationBinaryEncoder<kotlinx.serialization.cbor.Cbor>
org.springframework.http.codec.cbor.KotlinSerializationCborEncoder
All Implemented Interfaces:
Encoder<Object>

public class KotlinSerializationCborEncoder extends KotlinSerializationBinaryEncoder<kotlinx.serialization.cbor.Cbor>
Encode from an Object stream to a byte stream of CBOR objects using kotlinx.serialization. It supports application/cbor.

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 JSON encoders like JacksonCborEncoder without conflicts.

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

Since:
6.0
Author:
Iain Henderson, Sebastien Deleuze
See Also:
  • Constructor Details

    • KotlinSerializationCborEncoder

      public KotlinSerializationCborEncoder()
      Construct a new encoder using Cbor.Default instance which only encodes types annotated with @Serializable at type or generics level.
    • KotlinSerializationCborEncoder

      public KotlinSerializationCborEncoder(Predicate<ResolvableType> typePredicate)
      Construct a new encoder using Cbor.Default instance which only encodes types for which the specified predicate returns true.
      Since:
      7.0
    • KotlinSerializationCborEncoder

      public KotlinSerializationCborEncoder(kotlinx.serialization.cbor.Cbor cbor)
      Construct a new encoder using the provided Cbor instance which only encodes types annotated with @Serializable at type or generics level.
    • KotlinSerializationCborEncoder

      public KotlinSerializationCborEncoder(kotlinx.serialization.cbor.Cbor cbor, Predicate<ResolvableType> typePredicate)
      Construct a new encoder using the provided Cbor instance which only encodes types for which the specified predicate returns true.
      Since:
      7.0