You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Valentin (Jira)" <ji...@apache.org> on 2022/01/19 16:08:00 UTC

[jira] [Commented] (AVRO-2767) Can't easily use Java annotations to set enum default

    [ https://issues.apache.org/jira/browse/AVRO-2767?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17478793#comment-17478793 ] 

Valentin commented on AVRO-2767:
--------------------------------

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)