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 [One of "Under Discussion", "Accepted", "Rejected"]

Discussion threadhere

JIRAKAFKA-6923

Planned Release: 2.1.0

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

When headers were introduced by KIP-82 - Add Record Headers the change created the ExtendedSerializer and ExtendedDeserializer classes in order to keep interface compatibility but still add T deserialize(String topic, Headers headers, byte[] data); and byte[] serialize(String topic, Headers headers, T data); methods that consume the headers for serialization/deserialization. The reason for doing so was that Kafka at that time needed be compatbile with Java 7. Since we're not compiling on Java 7 anymore (KAFKA-4423) we should consolidate the way we're using these in a backward compatible fashion.

Public Interfaces

Two new interface methods will be created, which are the extra deserialize/serialize methods taken from the Extended classes:

Serializer
public interface Serializer<T> extends Closeable {

    void configure(Map<String, ?> configs, boolean isKey);
    byte[] serialize(String topic, T data);

    default byte[] serialize(String topic, Headers headers, T data) {                        // This is the new method
        return serialize(topic, data);
    }
    @Override
    void close();
}


Deserializer
public interface Deserializer<T> extends Closeable {
    void configure(Map<String, ?> configs, boolean isKey);
    T deserialize(String topic, byte[] data);

    default T deserialize(String topic, Headers headers, byte[] data) {                      // This is the new method
        return deserialize(topic, data);
    }

    @Override
    void close();
}

Proposed Changes

  1. Introduce the method above in both interfaces
  2. deprecate ExtendedSerializer/ExtendedDeserializer and Wrapper saying that new and existing implementations should use Serializer/Deserializer
  3. leave ExtendedSerializer/ExtendedDeserializer as is, so existing behavior won't change.
  4. get rid of the internal usages of ExtendedSerializer/ExtendedDeserializer & Wrapper.ensureExtended()

Compatibility, Deprecation, And Migration Plan

All changes should be backward compatible. The defined serialize/deserialize methods in ExtendedSerializer/ExtendedDeserializer will act as abstract overrides for the default methods which is valid. From the perspective of the implementors it shouldn't be a breaking change as the generated code in ExtendedSerializer/ExtendedDeserializer will remain the same.

Test Plan

Review existing unit tests and system tests.

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.

  • No labels