[
https://issues.apache.org/jira/browse/AVRO-3649?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18040163#comment-18040163
]
Long Tang commented on AVRO-3649:
---------------------------------
The 1.12.0 specification above said that any type in the union can be the
default value but in some places, this has NOT been implemented as of Dec 2025.
For example: This is the Avro code that can only handle the first type in a
union as the default value.
[https://github.com/apache/avro/blob/3ab4c4622d254b69e559690753075119c31782d6/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java#L119]
The IdlUtils uses the code above and fails to generate Avro schema in IDL if
the schema contains union fields with default values that are NOT the 1st
element of the union.
> [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
> Assignee: Christophe Le Saec
> Priority: Trivial
> Labels: pull-request-available
> Fix For: 1.12.0
>
> Time Spent: 3h 40m
> 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)