Class KotlinSerializationProtobufDecoder

java.lang.Object
org.springframework.http.codec.KotlinSerializationSupport<kotlinx.serialization.protobuf.ProtoBuf>
org.springframework.http.codec.KotlinSerializationBinaryDecoder<kotlinx.serialization.protobuf.ProtoBuf>
org.springframework.http.codec.protobuf.KotlinSerializationProtobufDecoder
All Implemented Interfaces:
Decoder<Object>

public class KotlinSerializationProtobufDecoder extends KotlinSerializationBinaryDecoder<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 decodes 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 KotlinSerializationProtobufDecoder(type -> true) will decode 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

    • KotlinSerializationProtobufDecoder

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

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

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

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