You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Zachary Payne (Jira)" <ji...@apache.org> on 2026/03/20 18:51:00 UTC

[jira] [Comment Edited] (AVRO-4211) IDLUtils cannot generate schema for union fields with a default value that is NOT the 1st element

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

Zachary Payne edited comment on AVRO-4211 at 3/20/26 6:50 PM:
--------------------------------------------------------------

Sample input:
{code:java}
public class TestObject {
    @Union({Void.class, String.class})
    @AvroDefault("\"Test String\"")
    public String myString = "Test String";
}{code}
Current output :
{code:java}
schema TestObject;

record TestObject {
    string? myString = null;
}{code}
Expected output:
{code:java}
schema TestObject;

record TestObject {
    string? myString = "Test String";
}{code}


was (Author: JIRAUSER312801):
Current sample output:

!image-2026-03-20-14-44-07-392.png!

Expected output:

!image-2026-03-20-14-44-46-833.png!

> IDLUtils cannot generate schema for union fields with a default value that is NOT the 1st element
> -------------------------------------------------------------------------------------------------
>
>                 Key: AVRO-4211
>                 URL: https://issues.apache.org/jira/browse/AVRO-4211
>             Project: Apache Avro
>          Issue Type: Improvement
>            Reporter: Long Tang
>            Assignee: Christophe Le Saec
>            Priority: Major
>
> The 1.12.0 specification 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. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)