Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-10477: Enabling the same behavior of NULL JsonNodeType to MISSI… #9306

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ private static Object convertToConnect(Schema schema, JsonNode jsonValue) {
} else {
switch (jsonValue.getNodeType()) {
case NULL:
case MISSING:
// Special case. With no schema
return null;
case BOOLEAN:
Expand All @@ -751,7 +752,6 @@ private static Object convertToConnect(Schema schema, JsonNode jsonValue) {
break;

case BINARY:
case MISSING:
case POJO:
default:
schemaType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ public void nullToConnect() {
assertEquals(SchemaAndValue.NULL, converted);
}

/**
* When schemas are disabled, empty data should be decoded to an empty envelope.
* This test verifies the case where `schemas.enable` configuration is set to false, and
* {@link JsonConverter} converts empty bytes to {@link SchemaAndValue#NULL}.
*/
@Test
public void emptyBytesToConnect() {
// This characterizes the messages with empty data when Json schemas is disabled
Map<String, Boolean> props = Collections.singletonMap("schemas.enable", false);
converter.configure(props, true);
SchemaAndValue converted = converter.toConnectData(TOPIC, "".getBytes());
assertEquals(SchemaAndValue.NULL, converted);
}

/**
* When schemas are disabled, fields are mapped to Connect maps.
*/
@Test
public void schemalessWithEmptyFieldValueToConnect() {
// This characterizes the messages with empty data when Json schemas is disabled
Map<String, Boolean> props = Collections.singletonMap("schemas.enable", false);
converter.configure(props, true);
String input = "{ \"a\": \"\", \"b\": null}";
SchemaAndValue converted = converter.toConnectData(TOPIC, input.getBytes());
Map<String, String> expected = new HashMap<>();
expected.put("a", "");
expected.put("b", null);
assertEquals(new SchemaAndValue(null, expected), converted);
}

@Test
public void nullSchemaPrimitiveToConnect() {
SchemaAndValue converted = converter.toConnectData(TOPIC, "{ \"schema\": null, \"payload\": null }".getBytes());
Expand Down