Bird
0
0

What is the recommended way to implement a custom SerDes for a Person class with fields name (String) and age (int)?

hard📝 Application Q8 of 15
Kafka - Advanced Stream Processing

What is the recommended way to implement a custom SerDes for a Person class with fields name (String) and age (int)?

AUse Kafka's built-in String serializer for both fields without custom code.
BCreate separate <code>PersonSerializer</code> and <code>PersonDeserializer</code> classes that convert <code>Person</code> objects to/from byte arrays, then combine them in a <code>PersonSerDe</code> class.
CSerialize the <code>Person</code> object by calling <code>toString()</code> and deserialize by parsing the string manually.
DStore the <code>Person</code> object as JSON in a file and read it during deserialization.
Step-by-Step Solution
Solution:
  1. Step 1: Understand custom SerDes design

    Custom SerDes typically involve separate serializer and deserializer classes.
  2. Step 2: Implement serialization logic

    Serializer converts Person fields to bytes; deserializer reconstructs Person from bytes.
  3. Step 3: Combine serializer and deserializer

    Wrap both in a SerDe class for Kafka Streams compatibility.
  4. Final Answer:

    Create separate PersonSerializer and PersonDeserializer classes and combine them in a PersonSerDe class. -> Option B
  5. Quick Check:

    Separate serializer/deserializer combined in SerDe [OK]
Quick Trick: Use separate serializer and deserializer classes combined [OK]
Common Mistakes:
  • Using toString() for serialization without format guarantees
  • Relying on built-in serializers for complex objects
  • Storing data externally instead of in Kafka messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes