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
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 Summary
ConstructorsConstructorDescriptionConstruct a new decoder usingProtoBuf.Defaultinstance which only decodes types annotated with@Serializableat type or generics level.KotlinSerializationProtobufDecoder(Predicate<ResolvableType> typePredicate) Construct a new decoder usingProtoBuf.Defaultinstance which only decodes types for which the specified predicate returnstrue.KotlinSerializationProtobufDecoder(kotlinx.serialization.protobuf.ProtoBuf protobuf) Construct a new decoder using the providedProtoBufinstance which only decodes types annotated with@Serializableat type or generics level.KotlinSerializationProtobufDecoder(kotlinx.serialization.protobuf.ProtoBuf protobuf, Predicate<ResolvableType> typePredicate) Construct a new decoder using the providedProtoBufinstance which only decodes types for which the specified predicate returnstrue. -
Method Summary
Methods inherited from class KotlinSerializationBinaryDecoder
canDecode, decode, decodeToMono, getDecodableMimeTypes, getDecodableMimeTypes, getMaxInMemorySize, setMaxInMemorySizeMethods inherited from class KotlinSerializationSupport
canSerialize, format, serializer, supportedMimeTypes
-
Constructor Details
-
KotlinSerializationProtobufDecoder
public KotlinSerializationProtobufDecoder()Construct a new decoder usingProtoBuf.Defaultinstance which only decodes types annotated with@Serializableat type or generics level. -
KotlinSerializationProtobufDecoder
Construct a new decoder usingProtoBuf.Defaultinstance which only decodes types for which the specified predicate returnstrue.- Since:
- 7.0
-
KotlinSerializationProtobufDecoder
public KotlinSerializationProtobufDecoder(kotlinx.serialization.protobuf.ProtoBuf protobuf) Construct a new decoder using the providedProtoBufinstance which only decodes types annotated with@Serializableat type or generics level. -
KotlinSerializationProtobufDecoder
public KotlinSerializationProtobufDecoder(kotlinx.serialization.protobuf.ProtoBuf protobuf, Predicate<ResolvableType> typePredicate) Construct a new decoder using the providedProtoBufinstance which only decodes types for which the specified predicate returnstrue.- Since:
- 7.0
-