Class KotlinSerializationProtobufEncoder

java.lang.Object
org.springframework.http.codec.KotlinSerializationSupport<kotlinx.serialization.protobuf.ProtoBuf>
org.springframework.http.codec.KotlinSerializationBinaryEncoder<kotlinx.serialization.protobuf.ProtoBuf>
org.springframework.http.codec.protobuf.KotlinSerializationProtobufEncoder
All Implemented Interfaces:
Encoder<Object>

public class KotlinSerializationProtobufEncoder extends KotlinSerializationBinaryEncoder<kotlinx.serialization.protobuf.ProtoBuf>
Decode a byte stream into a Protocol Buffer and convert to Objects with kotlinx.serialization. It supports application/x-protobuf, application/octet-stream, and application/vnd.google.protobuf.

As of Spring Framework 7.0, by default it only encodes types annotated with @Serializable at type or generics level.

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

Decoding streams is not supported yet, see kotlinx.serialization/issues/1073 related issue.

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

    • KotlinSerializationProtobufEncoder

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

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

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

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