Skip to content
1 change: 1 addition & 0 deletions sdks/java/extensions/avro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def avroVersions = [
'182' : "1.8.2",
'192' : "1.9.2",
'1102': "1.10.2",
'1120': "1.12.0",
]

avroVersions.each { k, v ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pholser.junit.quickcheck.From;
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
Expand Down Expand Up @@ -284,10 +285,21 @@ public void avroToBeamRoundTrip(
Iterable iterable = randomData(avroSchema, 10);
List<GenericRecord> records = Lists.newArrayList((Iterable<GenericRecord>) iterable);

// AVRO-4139: GenericRecord.equals() throws "Can't compare maps!" for records with
// nested map types on Avro 1.12.0. Fall back to JSON tree comparison on that version
// only; keep direct equals for other versions.
String avroVersion = org.apache.avro.Schema.class.getPackage().getImplementationVersion();
boolean useJsonCompare = "1.12.0".equals(avroVersion);
ObjectMapper mapper = useJsonCompare ? new ObjectMapper() : null;

for (GenericRecord record : records) {
Row row = AvroUtils.toBeamRowStrict(record, schema);
GenericRecord out = AvroUtils.toGenericRecord(row, avroSchema);
assertEquals(record, out);
if (useJsonCompare) {
assertEquals(mapper.readTree(record.toString()), mapper.readTree(out.toString()));
} else {
assertEquals(record, out);
}
}
}

Expand Down
Loading