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

Add support for java annotations containing elements

    XMLWordPrintableJSON

Details

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

    Description

      Currently it seems AVRO only supports java annotations that do not containĀ elements (which are basically the parameters to the annotation).

      Here's a stack overflow issue which shows an example of this.

      It would be useful to have this feature because many java annotations require elements, and not supporting this means only a small portion of java annotations can be supported.

      An example use case would be: I want to store data in avro that I'm getting from a 3rd party service as a JSON response, and I want my AVRO idl file to have different field names from the response body. If I'm using GSON, or any other JSON parser that uses annotations to configure alternative name mapping, then there's no easy way to do this.

      To be more explicit, if I had a json response

      {
         "name": "Jeff"
      }
      

      and an avro file

      protocol Response {
        record Response {
          string @javaAnnotation("com.google.gson.annotations.SerializedName") userName;
        }
      }
      

      Then there's no way to tell the GSON annotation about the alternate name is "name". In java you would just use:

      public class Response {
          @com.google.gson.annotations.SerializedName("name")
          String userName;
      }
      

      Supporting this feature would allow the generated java classes to be easily reused throughout the different layers of an app.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rstull1250 Ryan Stull
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: