Let's say I used avro-tools to generate code for v2 of "mySchema", and a message comes on a queue that was written with v1 of "mySchema". If I understand right, the best way to handle the situation is to realize that the message was written with v1 of "mySchema", get the v1 schema using a schema registry, and deserialize the message using v1.
At this point, is it at all possible to somehow convert the resulting objects into the corresponding fields and objects from the avro-tools generated code for v2?
So far, it looks like the only way to handle the message results in a "GenericRecord" which requires string keys to access the values of the fields. I'd much prefer to use the generated code for v2 and turn any typos into compile errors instead of runtime errors, know the data type of the value while coding, and avoid setting up a bunch of enums to contain the string keys.
Scott on the Avro users mailing list answered (https://lists.apache.org/thread.html/r2e77597fd20de1379fdd4287c02fc703a631cd2309f74f33d6a457b8%40%3Cuser.avro.apache.org%3E):
My mistake was missing the
T
onnew SpecificDatumReader<T>
, so it was returning aGenericRecord
instead of an instance ofT
.