[
https://issues.apache.org/jira/browse/AVRO-2767?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17478793#comment-17478793
]
Valentin edited comment on AVRO-2767 at 1/19/22, 4:07 PM:
----------------------------------------------------------
The use-case is to add it to fields where your enum is used.
This way you can have different default values depending on where the enum is
being used.
{code:java}
@AvroDefault("\"GREEN\"")
private Color color; {code}
was (Author: idkw0):
The use-case is to add it to fields where you enum is used.
As such you can have different default values depending on where it is used.
{code:java}
@AvroDefault("\"GREEN\"")
private Color color; {code}
> Can't easily use Java annotations to set enum default
> -----------------------------------------------------
>
> Key: AVRO-2767
> URL: https://issues.apache.org/jira/browse/AVRO-2767
> Project: Apache Avro
> Issue Type: Improvement
> Components: java
> Affects Versions: 1.9.2
> Reporter: Rich DiCroce
> Priority: Major
>
> 1.9.0 introduced support for enum default values. There's currently not an
> easy way to set an enum's default value when using Java annotations:
> * AvroDefault cannot be applied to a class.
> * AvroMeta can be applied to a class, but has no effect on an enum class.
> Not sure if that's a bug or not. Even if it could, "default" is a reserved
> name so presumably that would cause an error.
> The only solution I can find is to apply AvroSchema to the enum class and
> define everything, even though the only thing I want to set is the default.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)