Jan Scheidegger created AVRO-4245:
-------------------------------------
Summary: Property java-class is no longer read with FastReader
Key: AVRO-4245
URL: https://issues.apache.org/jira/browse/AVRO-4245
Project: Apache Avro
Issue Type: Bug
Affects Versions: 1.12.1
Reporter: Jan Scheidegger
With the switch to FastReader being the default we encountered the following
error during parsing messages.
```
java.lang.ClassCastException: class org.apache.avro.util.Utf8 cannot be cast to
class java.lang.String (org.apache.avro.util.Utf8 is in unnamed module of
loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
```
Reproducable as a UnitTest:
```
@Test
void testJavaType() {
// switch this to false to see it work without FastReader
GenericData model = SpecificData.get().setFastReaderEnabled(true);
final Schema writeSchema = SchemaBuilder.builder()
.stringBuilder()
.prop("java-class", "java.lang.String")
.endString();
final byte[] serialized;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Encoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
DatumWriter<String> w = new GenericDatumWriter<>(writeSchema, model);
w.write("hallo", encoder);
encoder.flush();
serialized= baos.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException((ioe));
}
final Schema readSchema = SchemaBuilder.builder()
.stringBuilder()
.prop("java-class", "java.lang.String")
.endString();
final Object deserialized;
try (ByteArrayInputStream bais = new ByteArrayInputStream(serialized)) {
Decoder decoder = DecoderFactory.get().directBinaryDecoder(bais, null);
DatumReader<?> r = new GenericDatumReader<>(writeSchema, readSchema, model);
deserialized = r.read(null, decoder);
System.out.println(deserialized.toString());
} catch (IOException ioe) {
throw new RuntimeException((ioe));
}
}
```
--
This message was sent by Atlassian Jira
(v8.20.10#820010)