Package dev.restate.sdk.common
Interface Serde<T>
public interface Serde<T>
Interface defining serialization and deserialization of concrete types.
Serde implementations are provided in JsonSerdes
in sdk-api
, KtSerdes
in sdk-api-kotlin
, JacksonSerdes
in sdk-serde-jackson
,
ProtobufSerdes
in sdk-serde-protobuf
.
You can create a custom one using using(String, ThrowingFunction, ThrowingFunction)
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Serde<ByteBuffer>
Pass throughSerde
forByteBuffer
.static final Serde<byte[]>
Pass throughSerde
for byte array.NoopSerde
for void. -
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable String
Content-type to use in request/responses.deserialize
(byte[] value) default T
deserialize
(ByteBuffer byteBuffer) byte[]
default ByteBuffer
serializeToByteBuffer
(@Nullable T value) static <T> Serde<T>
using
(ThrowingFunction<T, byte[]> serializer, ThrowingFunction<byte[], T> deserializer) Likeusing(String, ThrowingFunction, ThrowingFunction)
, using content-typeapplication/octet-stream
.static <T> Serde<T>
using
(String contentType, ThrowingFunction<T, byte[]> serializer, ThrowingFunction<byte[], T> deserializer) static <T> Serde<T>
withContentType
(String contentType, Serde<T> inner)
-
Field Details
-
VOID
NoopSerde
for void. -
RAW
Pass throughSerde
for byte array. -
BYTE_BUFFER
Pass throughSerde
forByteBuffer
.
-
-
Method Details
-
serialize
-
serializeToByteBuffer
-
deserialize
-
deserialize
-
contentType
Content-type to use in request/responses.If null, the SDK assumes the produced output is empty. This might change in the future.
-
using
static <T> Serde<T> using(ThrowingFunction<T, byte[]> serializer, ThrowingFunction<byte[], T> deserializer) Likeusing(String, ThrowingFunction, ThrowingFunction)
, using content-typeapplication/octet-stream
. -
using
static <T> Serde<T> using(String contentType, ThrowingFunction<T, byte[]> serializer, ThrowingFunction<byte[], T> deserializer) Create aSerde
fromserializer
/deserializer
lambdas, tagging withcontentType
. Before invoking the serializer, we check thatvalue
is non-null. -
withContentType
-