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 @@ -475,6 +475,16 @@ public int findLabel(String label) {
return i;
}
}
// AVRO-4135 We are a bit more flexible here since we have to deal with the C
// serializer being less strict, so
// we fall back to looking up unqualified names.
for (int i = 0; i < labels.length; i++) {
String candidate = labels[i];
if (candidate != null && candidate.length() > label.length()
&& candidate.charAt(candidate.length() - label.length() - 1) == '.' && candidate.endsWith(label)) {
return i;
}
}
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ void testIntWithError() throws IOException {
JsonDecoder decoder = DecoderFactory.get().jsonDecoder(schema, record);
Assertions.assertThrows(AvroTypeException.class, () -> reader.read(null, decoder));
}

@Test
void testUnionTypeQualification() throws Exception {
final Schema schema = SchemaBuilder.unionOf().nullType().and()
.type(SchemaBuilder.record("r").namespace("space").fields().endRecord()).endUnion();
GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema, schema);
JsonDecoder decoder = DecoderFactory.get().jsonDecoder(schema, "{\"space.r\": {}}");
assertEquals("space.r", reader.read(null, decoder).getSchema().getFullName());
// AVRO-4135: C json encoder uses unqualified types.
decoder = DecoderFactory.get().jsonDecoder(schema, "{\"r\": {}}");
assertEquals("space.r", reader.read(null, decoder).getSchema().getFullName());
}
}