You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Brian Cullen (Jira)" <ji...@apache.org> on 2020/12/21 07:49:00 UTC
[jira] [Created] (AVRO-3010) Support for Meta Annotations when
using Schema Annotations on Java Objects
Brian Cullen created AVRO-3010:
----------------------------------
Summary: Support for Meta Annotations when using Schema Annotations on Java Objects
Key: AVRO-3010
URL: https://issues.apache.org/jira/browse/AVRO-3010
Project: Apache Avro
Issue Type: Improvement
Components: java
Reporter: Brian Cullen
I'd like to propose (and offer to implement) support for meta annotations when using the schema annotations from the org.apache.avro.reflect package to generate schemas from Java POJOs.
As a simple example from my use case consider a object that could hold a number of optional UUIDs. Currently I would probably annotate it as follows.
{code:java}
@AvroMeta(key = "logicalType", value = "UUID")
@Nullable
private String someUUID;
{code}
Whereas if the use of meta annotation were allowed you could define an annotation along these lines to use instead.
{code:java}
@AvroMeta(key = "logicalType", value = "UUID")
@Nullable
public @interface OptionalUUID {
}
{code}
An additional benefit is where custom annotations are already being used on the class for validation or persistence purposes these annotation could be updated without having to change the annotated code at all.
I have experimented with this idea in the code base and it does appear to work, although there are some details that would need to be confirmed. The changes required involve changing how annotation are accessed in the ReflectData class and updating the target annotation of the existing annotations to include ElementType.ANNOTATION_TYPE, so that they can be applied to other annotations.
On the surface this change does not appear to be a large one and should not affect existing functionality. It would however give developers the ability to cut down on repeated code if they are using annotation a lot.
Do you think this fits in with the rest of the system or are there issues that I'm not aware of?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)