You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Status

Current state: Under Discussion

Discussion thread: here 

JIRA: KAFKA-8455 

Motivation

Often, when reading an input topic, the key is expected to be null, but there's actually no way to represent this fact in Consumed, leading to confusing type signatures down the topology. For example, you might use the BytesSerde, but then you have a KStream<Bytes,...>. When maintaining a large application, this becomes a hazard, since you'd need to "be really careful" not to try and dereference the key at any point, since you actually know it's always null.

Public Interfaces

I propose to add the following new SerDe:


NothingSerde
static public final class NothingSerde extends WrapperSerde<Void> {
    public NullSerde() {
        super(new NullSerializer(), new NullDeserializer());
    }
}

public class NullSerializer implements Serializer<Void> {
    @Override public byte[] serialize(String topic, Void data) {
        return new byte[0];
    }
}

public class NullDeserializer implements Deserializer<Void> {
    @Override public Void deserialize(String topic, byte[] data) {
        return null;
    }
}


Proposed Changes

I want to add NothingSerde to main SerDe collection.

Compatibility, Deprecation, and Migration Plan

There is no compatibility issues here.

Rejected Alternatives

One might use the BytesSerde, but then you have a KStream<Bytes,...>. When maintaining a large application, this becomes a hazard, since you'd need to "be really careful" not to try and dereference the key at any point, since you actually know it's always null.

  • No labels