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

Java: Additional annotations for reflection

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • java
    • avro java annotations

    Description

      I added three java annotations to the reflect package: @AvroIgnore, @AvroName and @AvroMetadata.

      Fields with the @AvroIgnore annotation will be treated as if they had a transient modifier, i.e. they will not be written to or rad from avro files.

      Java fields with the @AvroName("alt_name") annotation will be renamed in the induced schema.
      When reading an avro file into a new class via reflection, the reflection reader will also look for fields in the schema with the avro name.
      For example, schema 'example' could be read into the class 'exampleClass'.

      class exampleClass {
         @Avroname("foo")
         int bar;  
      }
      
      {
        "type" : "record",
        "name" : "example",
        "fields" : [ {"name" : "foo", "type" : "int" } ]
      }
      

      The @AvroMetadata(key="KEY", value="VALUE") annotation allows you to put an arbitrary key : value pair at every node in the schema.

      @AvroMetadata(key="classKey", value="classValue")
      class exampleClass {
      
         @AvroMetadata(key="fieldKey", value="fieldValue")
         int foo;  
         
      }
      
      {
        "type" : "record",
        "name" : "example",
        "fields" : [ {"name" : "foo", "type" : "int", "fieldKey" : "fieldValue" } ];
        "classKey" : "classValue"
      }
      

      I also extended the @Stringable annotation to java fields.
      This way one can turn objects to strings where the annotation cannot be added to the class itself.

      Attachments

        1. Avro-1328 update.patch
          19 kB
          Vincenz Priesnitz
        2. AVRO-1328.patch
          6 kB
          Vincenz Priesnitz

        Issue Links

          Activity

            People

              vince83 Vincenz Priesnitz
              vince83 Vincenz Priesnitz
              Votes:
              6 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: