Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1601

Subclasses of Avro generated SpecificRecordBase classes should be considered 'Specific classes'.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java
    • 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?

      [1] http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/reflect/FieldUtils.html#getAllFieldsList%28java.lang.Class%29

      Attachments

        Activity

          People

            Unassigned Unassigned
            ottomata Andrew Otto
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: