Current state: Accepted

Discussion thread:

JIRA KAFKA-8713 - Getting issue details... STATUS

Release: 3.5.0


JsonConverter is used by Connect to convert raw JSON payloads, in bytes, to and from Connect schemas an values objects. When converting Connect objects to bytes, if the value is null and the field has a default value, JsonConverter always emits the default value. In some cases, for example when the value is explicitly set to null, it would be preferable to keep the null value instead.

In particular, if we use Debezium to stream changes out of a table, t1, in mysql:

create table t1 {
   name varchar(40) not null,
   create_time datetime default '1999-01-01 11:11:11' null,
   update_time datetime default '1999-01-01 11:11:11' null

and then insert one record into table t1,

INSERT INTO `t1` (`name`, `update_time`) VALUES ('kafka', null);

the record will store in MySQL as:

  "name": "kafka",
  "create_time": "1999-01-01 11:11:11",
  "update_time": null

but the JsonConverter will always emit

  "name": "kafka",
  "create_time": "1999-01-01 11:11:11",
  "update_time": "1999-01-01 11:11:11"

It would be beneficial to be able to specify whether fields with a default value and set to null should be converted to null or the default value.

Public Interfaces

Add a configuration to JsonConverter:

Name: replace.null.with.default
Description: Whether to replace fields that have a default value and that are null to the default value. When set to true, the default value is used, otherwise null is used.
Type: Boolean
Default: true

Proposed Changes

Update JsonConverter and JsonConverterConfig to handle the new configuration. It will affect serialization when the converter runs in a source pipeline and deserialization in sink pipelines.

Compatibility, Deprecation, and Migration Plan

The new configuration keeps the current behavior by default so it will not affect existing users. Users can optionally opt-in the new behavior by setting the configuration to false.

Rejected Alternatives

  1. Always take null on a null field which has default value. It will break the compatibility.
  2. Add the configuration to ConverterConfig
  • No labels