Skip to content

AVRO-4211: Java Schema Gen for Unions w/ Default Value#3709

Open
zakpayne8283 wants to merge 1 commit intoapache:mainfrom
capitalone-contributions:avro-4211-java-idl-generation-union-defaults
Open

AVRO-4211: Java Schema Gen for Unions w/ Default Value#3709
zakpayne8283 wants to merge 1 commit intoapache:mainfrom
capitalone-contributions:avro-4211-java-idl-generation-union-defaults

Conversation

@zakpayne8283
Copy link
Copy Markdown

What is the purpose of the change

This PR addresses AVRO-4211. In Java, the IDLUtils does not generate Schemas correctly for fields which are unions and have a default value if the default value is not the first element in the union.

For example:

@Union({ Void.class, Integer.class })
@AvroDefault("1")
int someIntField = 1

Will produce a Schema like

someIntField = null

because Void.class is the first element in the union.

This change aligns the Java library with the current documentation:

Note that when a default value is specified for a record field whose type is a union, the type of the default value must match with one element of the union.

Verifying this change

This change modified tests and can be verified as follows:

Modified TestJacksonUtils.java, adding a union with default value matching the second element of the union to the testToObject() test.

Documentation

  • Does this pull request introduce a new feature?
    • No

@github-actions github-actions bot added the Java Pull Requests for Java binding label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant