Interface Deserializer<T>

Type Parameters:
T - Type to be deserialized into.
All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
BooleanDeserializer, ByteArrayDeserializer, ByteBufferDeserializer, BytesDeserializer, DoubleDeserializer, FloatDeserializer, IntegerDeserializer, ListDeserializer, LongDeserializer, SessionWindowedDeserializer, ShortDeserializer, StringDeserializer, TimeWindowedDeserializer, UUIDDeserializer, VoidDeserializer

public interface Deserializer<T> extends Closeable
An interface for converting bytes to objects. A class that implements this interface is expected to have a constructor with no parameters.

This interface can be combined with ClusterResourceListener to receive cluster metadata once it's available, as well as Monitorable to enable the deserializer to register metrics. For the latter, the following tags are automatically added to all metrics registered: config set to either key.deserializer or value.deserializer, and class set to the deserializer class name.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Close this deserializer.
    default void
    configure(Map<String,?> configs, boolean isKey)
    Configure this class.
    deserialize(String topic, byte[] data)
    Deserialize a record value from a byte array into a value or object.
    default T
    deserialize(String topic, Headers headers, byte[] data)
    Deserialize a record value from a byte array into a value or object.
    default T
    deserialize(String topic, Headers headers, ByteBuffer data)
    Deserialize a record value from a ByteBuffer into a value or object.
  • Method Details

    • configure

      default void configure(Map<String,?> configs, boolean isKey)
      Configure this class.
      Parameters:
      configs - configs in key/value pairs
      isKey - whether the deserializer is used for the key or the value
    • deserialize

      T deserialize(String topic, byte[] data)
      Deserialize a record value from a byte array into a value or object.

      It is recommended to deserialize a null byte array to a null object.

      Parameters:
      topic - topic associated with the data
      data - serialized bytes; may be null
      Returns:
      deserialized typed data; may be null
    • deserialize

      default T deserialize(String topic, Headers headers, byte[] data)
      Deserialize a record value from a byte array into a value or object.

      It is recommended to deserialize a null byte array to a null object.

      Note that the passed in Headers may be empty, but never null. The implementation is allowed to modify the passed in headers, as a side effect of deserialization. It is considered best practice to not delete or modify existing headers, but rather only add new ones.

      Parameters:
      topic - topic associated with the data
      headers - headers associated with the record
      data - serialized bytes; may be null
      Returns:
      deserialized typed data; may be null
    • deserialize

      default T deserialize(String topic, Headers headers, ByteBuffer data)
      Deserialize a record value from a ByteBuffer into a value or object.

      If ByteBufferDeserializer is used by an application, the application code cannot make any assumptions about the returned ByteBuffer like the position, limit, capacity, etc., or if it is backed by an array or not.

      Similarly, if this method is overridden, the implementation cannot make any assumptions about the passed in ByteBuffer either.

      It is recommended to deserialize a null ByteBuffer to a null object.

      Note that the passed in Headers may be empty, but never null. The implementation is allowed to modify the passed in headers, as a side effect of deserialization. It is considered best practice to not delete or modify existing headers, but rather only add new ones.

      Parameters:
      topic - topic associated with the data
      headers - headers associated with the record
      data - serialized ByteBuffer; may be null
      Returns:
      deserialized typed data; may be null
    • close

      default void close()
      Close this deserializer.

      This method must be idempotent as it may be called multiple times.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable