Interface Serde<T extends @Nullable Object>

All Superinterfaces:
TypeTag<T>

@NullMarked public interface Serde<T extends @Nullable Object> extends TypeTag<T>
Interface defining serialization and deserialization of concrete types.

For more info on the serialization stack, and how to customize it, see SerdeFactory.

Implementations MUST be thread safe.

You can create a custom one using using(String, ThrowingFunction, ThrowingFunction).

See Also:
  • Field Details

    • VOID

      static final Serde<@Nullable Void> VOID
      Noop Serde for void.
    • RAW

      static final Serde<byte[]> RAW
      Pass through Serde for byte array.
    • SLICE

      static final Serde<Slice> SLICE
      Passthrough serializer/deserializer
  • Method Details

    • serialize

      Slice serialize(T value)
    • deserialize

      T deserialize(Slice value)
    • contentType

      default @Nullable String contentType()
      Content-type to use in request/responses.

      If null, the SDK assumes the produced output is empty. This might change in the future.

    • jsonSchema

      default @Nullable Serde.Schema jsonSchema()
      Returns:
      a Draft 2020-12 Json Schema. It should be self-contained, and MUST not contain refs to files or HTTP. The schema is currently used by Restate to introspect the service contract and generate an OpenAPI definition.
    • using

      static <T extends @NonNull Object> Serde<@NonNull T> using(ThrowingFunction<T,byte[]> serializer, ThrowingFunction<byte[],T> deserializer)
      Like using(String, ThrowingFunction, ThrowingFunction), using content-type application/octet-stream.
    • using

      static <T extends @NonNull Object> Serde<@NonNull T> using(String contentType, ThrowingFunction<T,byte[]> serializer, ThrowingFunction<byte[],T> deserializer)
      Create a Serde from serializer/deserializer lambdas, tagging with contentType. Before invoking the serializer, we check that value is non-null.
    • withContentType

      static <T> Serde<T> withContentType(String contentType, Serde<T> inner)