Bird
0
0

You want to send JSON objects to a Kafka topic and receive them as Java objects in Spring Boot. Which configuration is necessary?

hard📝 Application Q8 of 15
Spring Boot - Messaging
You want to send JSON objects to a Kafka topic and receive them as Java objects in Spring Boot. Which configuration is necessary?
AConfigure KafkaTemplate and @KafkaListener with JSON serializer and deserializer
BUse String serializer and deserialize manually in listener
CNo configuration needed; Kafka handles JSON automatically
DUse @KafkaJsonListener annotation instead of @KafkaListener
Step-by-Step Solution
Solution:
  1. Step 1: Understand serialization and deserialization

    Kafka needs serializers to convert Java objects to JSON and deserializers to convert JSON back to Java objects.
  2. Step 2: Apply correct configuration

    KafkaTemplate and @KafkaListener must be configured with JSON serializer/deserializer to handle JSON automatically.
  3. Final Answer:

    Configure KafkaTemplate and @KafkaListener with JSON serializer and deserializer -> Option A
  4. Quick Check:

    JSON serialization requires explicit config [OK]
Quick Trick: Set JSON serializer/deserializer for object messages [OK]
Common Mistakes:
  • Assuming Kafka auto-handles JSON
  • Using String serializer for JSON objects
  • Looking for non-existent @KafkaJsonListener

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes