Serializers, Deserializers, and Serdes

111 views
Skip to first unread message

Tianxiang Xiong

unread,
Sep 14, 2016, 3:59:35 PM9/14/16
to Confluent Platform
I'm looking at the org.apache.kafka.common.serialization namespace, and wondering what the relationships between Serializer, Derserializer, and Serde are. Serializer and Deserializer seem pretty obvious as counterparts, but where does Serde fit in? Is it just a thin wrapper around a Serializer and the corresponding Deserializer?

For example, the Schema Registry's Avro Serializers package has implementations of Serializer and Deserializer, but none for Serde. Is this simply an oversight, or is the implementation of a KafkaAvroSerde considered simple enough to be "left as an exercise to the reader"? If the latter, is there a good example of creating Serde from Serializer and Derserializer?

Marek Svitok

unread,
Sep 15, 2016, 3:15:01 AM9/15/16
to Confluent Platform
Hi.

Serdes are just thin wrappers around Serializer and Deserializer. The name Serde means Serializer Deserializer. You need them everywhere within your stream toplogy definition.


final Serializer<JsonNode> jsonSerializer = new JsonSerializer();
final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer();
final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer);

KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input");

Hope this helps.
Marek.


Dňa streda, 14. septembra 2016 21:59:35 UTC+2 Tianxiang Xiong napísal(-a):

Tianxiang Xiong

unread,
Sep 15, 2016, 11:51:46 AM9/15/16
to Confluent Platform
OK, so it does appear to be trivial to define a Serde once you've got a Serializer and Derserializer.

Marek Svitok

unread,
Sep 16, 2016, 2:34:38 AM9/16/16
to Confluent Platform
Exactly.

Dňa štvrtok, 15. septembra 2016 17:51:46 UTC+2 Tianxiang Xiong napísal(-a):
Reply all
Reply to author
Forward
0 new messages