Bird
0
0

What will the deserializer return for input null in this code?

medium📝 Predict Output Q5 of 15
Kafka - Advanced Stream Processing

What will the deserializer return for input null in this code?

public String deserialize(String topic, byte[] data) {
    if (data == null) return null;
    return new String(data, StandardCharsets.UTF_8);
}
AString "null"
BEmpty string ""
Cnull
DThrows NullPointerException
Step-by-Step Solution
Solution:
  1. Step 1: Check null input handling

    If data is null, method returns null immediately.
  2. Step 2: Confirm no exception thrown

    Code explicitly returns null, so no exception or string conversion occurs.
  3. Final Answer:

    null -> Option C
  4. Quick Check:

    Deserialize null input returns null [OK]
Quick Trick: Deserializer returns null if input byte array is null [OK]
Common Mistakes:
MISTAKES
  • Expecting empty string instead of null
  • Assuming exception is thrown
  • Thinking it returns string "null"

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes