Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
The createSchema() method of SpecificData class calls getDeclaredField("SCHEMA$") to check if the class is a valid 'Specific' Avro schema class. It'd be nice if generated classes could be extended so convenience methods could be added without modifying the generated code itself.
E.g. I'd like to convert XML fragments into Avro records, and it would be nice if my the generated class contained the logic to do this, rather than keeping it in some utility class elsewhere. I'd like to extend the generated Avro schema class to add this functionality, but if I do so I can't call getSchema() on my record objects. If I try, I get: org.apache.avro.AvroRuntimeException: Not a Specific class: class org.wikimedia.mediawiki.Revision. This is because the SCHEMA$ field does not exist directly on the subclass, but on the generated (super)class only.
To do this, I think the check for the SCHEMA$ field should look at superclasses as well. Perhaps FieldUtils.getAllFieldList()[1] would do?