apache-kafkaCustom Serializer/Deserializer


Kafka stores and transports byte arrays in its queue. The (de)serializers are responsible for translating between the byte array provided by Kafka and POJOs.


  • public void configure(Map<String, ?> config, boolean isKey);
  • public T deserialize(String topic, byte[] bytes);
  • public byte[] serialize(String topic, T obj);


configthe configuration properties (Properties) passed to the Producer or Consumer upon creation, as a map. It contains regular kafka configs, but can also be augmented with user-defined configuration. It is the best way to pass arguments to the (de)serializer.
isKeycustom (de)serializers can be used for keys and/or values. This parameter tells you which of the two this instance will deal with.
topicthe topic of the current message. This lets you define custom logic based on the source/destination topic.
bytesThe raw message to deserialize
objThe message to serialize. Its actual class depends on your serializer.


Before version the Kafka Java API used Encoders and Decoders. They have been replaced by Serializer and Deserializer in the new API.