[ 
https://issues.apache.org/jira/browse/AVRO-2327?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ryan Stull updated AVRO-2327:
-----------------------------
    Description: 
Currently it seems AVRO only supports java annotations that do not containĀ 
[elements|https://docs.oracle.com/javase/tutorial/java/annotations/basics.html] 
(which are basically the parameters to the annotation).  

[Here's a stack overflow 
issue|https://stackoverflow.com/questions/54675764/how-to-supply-argument-to-a-javaannotation-on-an-avro-idl-file]
 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 

{code:json}
{
   "name": "Jeff"
}
{code}

and an avro file

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

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


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


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

  was:
Currently it seems AVRO only supports java annotations that do not containĀ 
[elements|https://docs.oracle.com/javase/tutorial/java/annotations/basics.html] 
(which are basically the parameters to the annotation).  

[Here's a stack overflow 
issue|https://stackoverflow.com/questions/54675764/how-to-supply-argument-to-a-javaannotation-on-an-avro-idl-file]
 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 

{code:json}
{
   "name": "Jeff"
}
{code}

and an avro file

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

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


{code:java}
public class Response {
    @com.google.gson.annotations.SerializedName("name")
    string userName;
}
{code}


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


> Add support for java annotations containing elements
> ----------------------------------------------------
>
>                 Key: AVRO-2327
>                 URL: https://issues.apache.org/jira/browse/AVRO-2327
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Ryan Stull
>            Priority: Minor
>              Labels: usability
>
> Currently it seems AVRO only supports java annotations that do not containĀ 
> [elements|https://docs.oracle.com/javase/tutorial/java/annotations/basics.html]
>  (which are basically the parameters to the annotation).  
> [Here's a stack overflow 
> issue|https://stackoverflow.com/questions/54675764/how-to-supply-argument-to-a-javaannotation-on-an-avro-idl-file]
>  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 
> {code:json}
> {
>    "name": "Jeff"
> }
> {code}
> and an avro file
> {code:js}
> protocol Response {
>   record Response {
>     string @javaAnnotation("com.google.gson.annotations.SerializedName") 
> userName;
>   }
> }
> {code}
> Then there's no way to tell the GSON annotation about the alternate name is 
> "name".  In java you would just use:
> {code:java}
> public class Response {
>     @com.google.gson.annotations.SerializedName("name")
>     String userName;
> }
> {code}
> Supporting this feature would allow the generated java classes to be easily 
> reused throughout the different service layers of an app.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to