[
https://issues.apache.org/jira/browse/AVRO-3649?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17621280#comment-17621280
]
Ryan Skraba commented on AVRO-3649:
-----------------------------------
I think this is a neat feature!
I made a comment on the PR, there's some convincing reasons to avoid exposing
{{JsonNode}} or other Jackson APIs in the public interface, especially one as
core as {*}Schema{*}.
What would you think about simply adding a parameter with a default to the
*{{@Nullable}}* annotation? Something like *nullFirst* with a default value of
{*}true{*}.
Alternatively, we could add a *withDefault* parameter to *{{@Nullable}}* with a
default of {*}null{*}. If it is set to anything else, then null should come
second in the generated union.
To be honest, both of those would avoid touching Schema, but I prefer your
"auto" solution better.
> [JAVA] reorder union types to match default value
> -------------------------------------------------
>
> Key: AVRO-3649
> URL: https://issues.apache.org/jira/browse/AVRO-3649
> Project: Apache Avro
> Issue Type: Improvement
> Reporter: Daniel Heinrich
> Priority: Trivial
> Labels: pull-request-available
> Time Spent: 1h
> Remaining Estimate: 0h
>
> The Avro specification requires that a default value matches the first schema
> of a union type.
>
> Using @Nullable on a field will return a union type of the form ["null",
> "<something>"].
> @Nullable also sets the default value to "null".
>
> It is not possible to override this default value w{color:#172b4d}ith
> @AvroDefault because of the order of the schemas in the generated
> union.{color}
>
> It would be nice that union types are automatically reordered to match the
> type of the provided default value.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)