Skip to content

Commit 30ec56c

Browse files
KAFKA-10477: Enabling the same behavior of NULL JsonNodeType to MISSING JsonNodeType in JsonConverter.
From 2.10.0 onwards, in jackson lib, ObjectMapper.readTree(input) started to return JsonNode of type MISSING for empty input, as mentioned in the issue: FasterXML/jackson-databind#2211. Made changes in JsonParser to incorporate this, and treat MISSING JsonNodeType in a similar fashion as that of NULL JsonNodeType. Added a unit test for this.
1 parent 9fda3d2 commit 30ec56c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

connect/json/src/main/java/org/apache/kafka/connect/json/JsonConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ private static Object convertToConnect(Schema schema, JsonNode jsonValue) {
729729
} else {
730730
switch (jsonValue.getNodeType()) {
731731
case NULL:
732+
case MISSING:
732733
// Special case. With no schema
733734
return null;
734735
case BOOLEAN:
@@ -751,7 +752,6 @@ private static Object convertToConnect(Schema schema, JsonNode jsonValue) {
751752
break;
752753

753754
case BINARY:
754-
case MISSING:
755755
case POJO:
756756
default:
757757
schemaType = null;

connect/json/src/test/java/org/apache/kafka/connect/json/JsonConverterTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ public void nullToConnect() {
195195
assertEquals(SchemaAndValue.NULL, converted);
196196
}
197197

198+
/**
199+
* When schemas are disabled, empty data should be decoded to an empty envelope.
200+
* This test verifies the case where `schemas.enable` configuration is set to false, and
201+
* {@link JsonConverter} converts empty bytes to {@link SchemaAndValue#NULL}.
202+
*/
203+
@Test
204+
public void emptyBytesToConnect() {
205+
// This characterizes the messages with empty data when Json schemas is disabled
206+
Map<String, Boolean> props = Collections.singletonMap("schemas.enable", false);
207+
converter.configure(props, true);
208+
SchemaAndValue converted = converter.toConnectData(TOPIC, "".getBytes());
209+
assertEquals(SchemaAndValue.NULL, converted);
210+
}
211+
198212
@Test
199213
public void nullSchemaPrimitiveToConnect() {
200214
SchemaAndValue converted = converter.toConnectData(TOPIC, "{ \"schema\": null, \"payload\": null }".getBytes());

0 commit comments

Comments
 (0)