Versions Compared

Key

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

Table of Contents

Status

Current state:  Under DiscussionAccepted

Discussion thread: https://lists.apache.org/thread/lxfq8y8co76mjwxhowwx6cjl0hw1mxpy

JIRA

Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyKAFKA-8713

Release: 3.5.0

Motivation

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.

...

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 two configurations a configuration to JsonConverter:

Name: serializereplace.usenull.optional.null
Description: Whether to serialize fields that have a default value and that are null to the default value or to null. When set to false, the default value is used, otherwise null is used.
Type: Boolean
Default: false
Name: deserialize.use.optional.null
with.default
Description: Whether to deserialize replace fields that have a default value and that are null to the default value or to null. When set to falsetrue, the default value is used, otherwise null is used.
Type: Boolean
Default: falsetrue

Proposed Changes

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

Compatibility, Deprecation, and Migration Plan

The new configurations keep 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 configurations configuration to truefalse.

Rejected Alternatives

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