Search code examples
javaannotationscode-generationavro

How to supply argument to a @javaAnnotation on an avro idl file?


I'm trying to add a java annotation to my avro idl file (avdl file). And I can't seem to figure out how to supply the arguments to the annotation. Here's a simplified example

protocol Message {
    record Message {
        int @javaAnnotation("java.lang.SuppressWarnings") myInt = 0;
    }
}

When I try to compile this I get

error: annotation @SuppressWarnings is missing a default value for the element 'value'
@java.lang.SuppressWarnings
  ^
1 error

But I don't really see any syntax that would allow me to pass the parameter. Here's the ticket that added this feature https://issues.apache.org/jira/browse/AVRO-1186 for reference.

I'm using avro version 1.8.2 and using the gradle-avro plugin version 0.12.0

I anyone could provide some insight, it would be much appreciated.


Solution

  • You may write the annotation as it would appear, escaping the double quotes:

    protocol Message {
        record Message {
            int @javaAnnotation("java.lang.SuppressWarnings(\"unused\")") myInt = 0;
        }
    }
    

    The Avro compiler does nothing to strip annotation names.