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

Support for Meta Annotations when using Schema Annotations on Java Objects

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java
    • None

    Description

      I'd like to propose (and offer to implement) support for meta annotations when using the schema annotations from the org.apache.avro.reflect package to generate schemas from Java POJOs. 

      As a simple example from my use case consider a object that could hold a number of optional UUIDs. Currently I would probably annotate it as follows.

      @AvroMeta(key = "logicalType", value = "UUID")
      @Nullable
      private String someUUID;
      

      Whereas if the use of meta annotation were allowed you could define an annotation along these lines to use instead.

      @AvroMeta(key = "logicalType", value = "UUID")
      @Nullable
      public @interface OptionalUUID {
      
      }
      

      An additional benefit is where custom annotations are already being used on the class for validation or persistence purposes these annotation could be updated without having to change the annotated code at all.

      I have experimented with this idea in the code base and it does appear to work, although there are some details that would need to be confirmed. The changes required involve changing how annotation are accessed in the ReflectData class and updating the target annotation of the existing annotations to include ElementType.ANNOTATION_TYPE, so that they can be applied to other annotations.

      On the surface this change does not appear to be a large one and should not affect existing functionality. It would however give developers the ability to cut down on repeated code if they are using annotation a lot.

      Do you think this fits in with the rest of the system or are there issues that I'm not aware of?

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            brian.cullen Brian Cullen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: