liveBook · Manning

Deserializer

As explained in Kafka Streams in Action, Second Edition

The Kafka Deserializer interface defines the API that a deserializer implementation uses to convert bytes into data.

A deserializer converts Kafka record bytes into an object a consumer can use. The consumer passes a byte array to deserialize and receives the expected object type. Producers and consumers remain decoupled from the conversion classes; configuration supplies the implementation. Because they evolve independently, the producer’s serialized object type and the consumer’s deserialized type form an implicit event contract. section 3.1

Figure 3.1 The conversion of objects to bytes and bytes to objects happens at the client level.
figure

Follow the conversion boundary: objects become bytes before reaching a Kafka topic, then bytes become objects after a consumer reads them. section 3.1

A Schema Registry–aware deserializer adds schema discovery to that conversion. After a consumer reads record bytes, it retrieves the needed schema over HTTP when absent from its local cache, then deserializes according to that schema. Registry-backed serializers and deserializers are available for Avro, Protobuf, and JSON Schema, helping standardize data handling and preserve schema validation. section 3.2.1 section 3.7

Configure an Avro consumer

Configure the consumer value deserializer as KafkaAvroDeserializer and provide the Schema Registry URL. Set SPECIFIC_AVRO_READER_CONFIG to true to receive generated specific Avro records and call typed accessors such as getName(); leave it false to receive a GenericRecord and access fields by name after checking that they exist. section 3.2.9

Schema Registry is optional. A custom class can implement org.apache.kafka.common.serialization.Deserializer, whose required method is deserialize; configure and close are default methods that may be overridden. A JSON-based implementation can pass the bytes and target object class to Jackson ObjectMapper.readValue, returning the reconstructed value or wrapping an IOException in SerializationException. section 3.8 section 3.8

Configure serialization classes on KafkaProducer or KafkaConsumer rather than invoking them directly. In Kafka Streams, use a Serde—a paired serializer and deserializer—because the embedded producer and consumer are not directly accessible. section 3.7

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains interface methods, Schema Registry caching, consumer configuration, and a Jackson custom implementation; defers producer and consumer client details.
Examples
Uses generated Avro records versus GenericRecord and a Jackson ObjectMapper.readValue custom deserializer.
What it assumes
Assumes only enough Kafka producer and consumer context to place deserialization, while deferring detailed client operation.
What you can do after
Build it from scratch by implementing Deserializer, or apply KafkaAvroDeserializer through Kafka consumer configuration.
How it connects
Connects Deserializer with Serializer, KafkaConsumer, Schema Registry, schemas, Serde, and Kafka Streams.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.