[
https://issues.apache.org/jira/browse/AVRO-1328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13654649#comment-13654649
]
Doug Cutting commented on AVRO-1328:
------------------------------------
These are great additions.
A few comments on the patch:
- We should add tests for all of these to TestReflect.java.
- I'd prefer calling it "AvroMeta" or "AvroProp" rather than "AvroMetadata".
- The code for field names can be simplified a bit, e.g:
{code}
AvroName annotatedName = field.getAnnotation(AvroName.class);
String fieldName = annotatedName == null
? annotatedName.value()
: field.getName();
Schema.Field recordField
= new Schema.Field(fieldName, fieldSchema, null, defaultValue);
{code}
> Java: Additional annotations for reflection
> -------------------------------------------
>
> Key: AVRO-1328
> URL: https://issues.apache.org/jira/browse/AVRO-1328
> Project: Avro
> Issue Type: New Feature
> Components: java
> Reporter: Vincenz Priesnitz
> Priority: Minor
> Attachments: AVRO-1328.patch
>
>
> I added three java annotations to the reflect package: @AvroIgnore, @AvroName
> and @AvroMetadata.
> Fields with the @AvroIgnore annotation will be treated as if they had a
> transient modifier, i.e. they will not be written to or rad from avro files.
> Java fields with the @AvroName("alt_name") annotation will be renamed in the
> induced schema.
> When reading an avro file into a new class via reflection, the reflection
> reader will also look for fields in the schema with the avro name.
> For example, schema 'example' could be read into the class 'exampleClass'.
> {code}
> class exampleClass {
> @Avroname("foo")
> int bar;
> }
> {code}
> {code}
> {
> "type" : "record",
> "name" : "example",
> "fields" : [ {"name" : "foo", "type" : "int" } ]
> }
> {code}
> The @AvroMetadata(key="KEY", value="VALUE") annotation allows you to put an
> arbitrary key : value pair at every node in the schema.
> {code}
> @AvroMetadata(key="classKey", value="classValue")
> class exampleClass {
> @AvroMetadata(key="fieldKey", value="fieldValue")
> int foo;
>
> }
> {code}
> {code}
> {
> "type" : "record",
> "name" : "example",
> "fields" : [ {"name" : "foo", "type" : "int", "fieldKey" : "fieldValue" } ];
> "classKey" : "classValue"
> }
> {code}
> I also extended the @Stringable annotation to java fields.
> This way one can turn objects to strings where the annotation cannot be added
> to the class itself.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira