0
0
Kafkadevops~10 mins

Custom SerDes in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to implement the serialize method in a custom Kafka Serializer.

Kafka
public byte[] serialize(String topic, [1] data) {
    if (data == null) {
        return null;
    }
    return data.getBytes(StandardCharsets.UTF_8);
}
Drag options to blanks, or click blank then click option'
Aint
BString
Cbyte[]
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or Object as the data type causes compile errors.
Using byte[] as input is incorrect because serialize expects the original data type.
2fill in blank
medium

Complete the code to implement the deserialize method in a custom Kafka Deserializer.

Kafka
public String deserialize(String topic, [1] data) {
    if (data == null) {
        return null;
    }
    return new String(data, StandardCharsets.UTF_8);
}
Drag options to blanks, or click blank then click option'
AObject
BString
Cint
Dbyte[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using String as input causes errors because data is raw bytes.
Using int or Object as input is incorrect.
3fill in blank
hard

Fix the error in the custom Serializer class declaration.

Kafka
public class CustomSerializer implements Serializer<[1]> {
    // implementation
}
Drag options to blanks, or click blank then click option'
AString
BInteger
Cbyte[]
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using byte[] or Object as generic type causes mismatch errors.
Using Integer when data is String causes type errors.
4fill in blank
hard

Fill both blanks to complete the custom Deserializer class declaration and method signature.

Kafka
public class CustomDeserializer implements Deserializer<[1]> {
    @Override
    public [2] deserialize(String topic, byte[] data) {
        if (data == null) return null;
        return new String(data, StandardCharsets.UTF_8);
    }
}
Drag options to blanks, or click blank then click option'
AString
Bbyte[]
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using byte[] as generic type or return type causes errors.
Mixing Object and String types causes type mismatch.
5fill in blank
hard

Fill all three blanks to complete the custom SerDes class with serializer, deserializer, and configure method.

Kafka
public class CustomSerDes implements Serializer<[1]>, Deserializer<[2]> {

    @Override
    public byte[] serialize(String topic, [3] data) {
        if (data == null) return null;
        return data.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public [2] deserialize(String topic, byte[] data) {
        if (data == null) return null;
        return new String(data, StandardCharsets.UTF_8);
    }

    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {
        // configuration code if needed
    }

    @Override
    public void close() {
        // cleanup code if needed
    }
}
Drag options to blanks, or click blank then click option'
AString
Bbyte[]
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using byte[] or Object as generic or parameter types causes type errors.
Mismatch between generic types and method parameter/return types.