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

Java Annotations via IDL

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.7.3
    • java
    • None
    • IDL Java Annotation Annotations

    Description

      We would like to have the ability to add Java annotations to fields in the Avro IDL (i.e. JSR 303 Bean Validation annotations). From a protocol stand point these annotations may not mean much (or could they?) but from the application stand point having this feature would allow developers to use Avro generated beans application wide. From view layer all the way to the data layer. To support this feature an IDL file could look something like this:

       
      @namespace("test.annotations")
      protocol TestProto {
      
        record User {
           //declare the annotations that are imported in the generated record class
           @header{
             import org.hibernate.validator.constraints.NotBlank;
             import org.hibernate.validator.constraints.Email;
           }  
       
           //for each field one can specify an annotation they would like to use.
           @{@NotBlank} string username;
           string password;
           @{@Email} string email;
        }
      
      }
      

      The above IDL would generate a Java class that looks something like this:

       
      /**
       * Autogenerated by Avro
       * 
       * DO NOT EDIT DIRECTLY
       */
      package com.simvia.mode.avro; 
      
      import org.hibernate.validator.constraints.NotBlank;
      import org.hibernate.validator.constraints.Email;
      
      @SuppressWarnings("all")
      public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
        ...
      
        @Deprecated @NotBlank public java.lang.CharSequence username;
        @Deprecated public java.lang.CharSequence password;
        @Deprecated @Email public java.lang.CharSequence email;
      
       ...
      
      }
      

      Perhaps this is too language specific but IMO the benefits of this feature in the Java world is worth the effort and the exception.

      Attachments

        1. AVRO-1186.patch
          11 kB
          Doug Cutting
        2. AVRO-1186.patch
          9 kB
          Doug Cutting

        Issue Links

          Activity

            People

              cutting Doug Cutting
              saden1 Sharmarke Aden
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: