Skip to content
Open
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 @@ -24,6 +24,7 @@
import org.bson.codecs.DocumentCodecProvider;
import org.bson.codecs.MapCodecProvider;
import org.bson.codecs.ValueCodecProvider;
import org.bson.codecs.IterableCodecProvider;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;

Expand All @@ -36,7 +37,8 @@ public class JsonSchemalessRecordConverter implements RecordConverter {
new DocumentCodecProvider(),
new BsonValueCodecProvider(),
new ValueCodecProvider(),
new MapCodecProvider()
new MapCodecProvider(),
new IterableCodecProvider()
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ public void transformRecordValue2JsonStringWithoutSchemaTest() {
assertEquals("{\"simpleString\": \"TestString\", \"simpleBoolean\": true, \"simpleFLOAT32\": 1.0, \"simpleFLOAT64\": 2.0, \"simpleInt8\": 8, \"simpleInt16\": 2, \"simpleInt32\": 3, \"simpleInt64\": 4, \"simpleBytes\": {\"$binary\": {\"base64\": \"S2Fma2Egcm9ja3Mh\", \"subType\": \"00\"}}, \"nestedArray1\": {\"entry\": \"testEntry\"}, \"nestedArray2\": {\"entry\": \"testEntry2\"}, \"simpleDate\": {\"$date\": \"2022-12-03T00:00:00Z\"}, \"simpleTime\": {\"$date\": \"2022-12-03T00:00:00Z\"}, \"simpleTimestamp\": {\"$date\": \"2022-12-03T12:00:00Z\"}, \"simpleDecimal\": {\"$numberDecimal\": \"12345.6789\"}}", jsonString);
}

@Test
public void transformRecordValue2JsonStringWithoutSchemaWithEmptyArrayListTest() {
// value for json format without schema
HashMap<String, Object> simpleValueWithoutSchema = new LinkedHashMap<>();
simpleValueWithoutSchema.put("emptyArrayList", new ArrayList<>());

final Map<String, Object> props = new HashMap<>();
props.put("json.string.field.name", "myawesomejsonstringfield");

valueSmt.configure(props);
final SinkRecord record = new SinkRecord(null, 0, null, null, null, simpleValueWithoutSchema, 0);
final SinkRecord transformedRecord = valueSmt.apply(record);

assertEquals(1, transformedRecord.valueSchema().fields().size());
assertEquals(Schema.STRING_SCHEMA,transformedRecord.valueSchema().field("myawesomejsonstringfield").schema());

Struct value = (Struct) transformedRecord.value();
String jsonString = (String) value.get("myawesomejsonstringfield");

assertEquals("{\"emptyArrayList\": []}", jsonString);
}

@Test
public void transformRecordValue2JsonStringLogicalTypesDatetimeAsStringTest() {
final Map<String, Object> props = new HashMap<>();
Expand Down