Bird
0
0

Given the following Kafka consumer code snippet, what will be the output if the message value is a JSON string but the deserializer is set to StringDeserializer?

medium📝 Predict Output Q13 of 15
Kafka - Consumers

Given the following Kafka consumer code snippet, what will be the output if the message value is a JSON string but the deserializer is set to StringDeserializer?

props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
ConsumerRecord<String, String> record = consumer.poll(Duration.ofMillis(100)).iterator().next();
System.out.println(record.value());
ABinary data printed as garbage characters
BThe JSON string as plain text
CNull value printed
DA deserialization error exception
Step-by-Step Solution
Solution:
  1. Step 1: Understand StringDeserializer behavior

    StringDeserializer converts bytes to a UTF-8 string without parsing JSON.
  2. Step 2: Output of printing record.value()

    The JSON string is printed as plain text exactly as received.
  3. Final Answer:

    The JSON string as plain text -> Option B
  4. Quick Check:

    StringDeserializer outputs raw string [OK]
Quick Trick: StringDeserializer prints raw string, no JSON parsing [OK]
Common Mistakes:
  • Expecting automatic JSON parsing
  • Thinking deserialization fails on JSON strings
  • Assuming binary garbage output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes