Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As currently implementation, when isOptional() return true and defaultValue() return not null, in other word, an optional field which has default value, if we use org.apache.kafka.connect.json.JsonConverter will take the  to serialize the field, will eventually get defaultValue() as the field value. It make sense in most scenario.

...

Public Interfaces

Add a config property accept.optional.null, default false, for compatibility.

Proposed Changes

Config property change

Add a config property accept.optional.null in org.apache.kafka.connect.storage.ConverterConfig, default false. For a . This property would only affect JsonConverter in all build-in converters, both serialization and deserialization. Any third party converters can extend ConverterConfig just like JsonConverterConfig to read this property and implement it.

JsonConverter change

Change fields TO_CONNECT_CONVERTERS, LOGICAL_CONVERTERS, method convertToConnect(Schema schema, JsonNode jsonValue) to no-static.

Serialization(convertToJson), for an optional null field which has default value,

  • if set accept.optional.null=true, take null;
  • if set accept.optional.null=false, take default value.

Deserialization(convertToConnectData), for an optional null field which has default value,

  • if set accept.optional.null=true, take null;
  • if set accept.optional.null=false, take default value.

Compatibility, Deprecation, and Migration Plan

...

Rejected Alternatives

  1. Always take null on a an optional null field which has default value. It will break the compatibility and only cover partial cases.