You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Novian Suryana (Jira)" <ji...@apache.org> on 2020/11/11 23:27:00 UTC

[jira] [Created] (AVRO-2959) Set default to null for nullable when defaultGenerated is enabled in ReflectData

Novian Suryana created AVRO-2959:
------------------------------------

             Summary: Set default to null for nullable when defaultGenerated is enabled in ReflectData
                 Key: AVRO-2959
                 URL: https://issues.apache.org/jira/browse/AVRO-2959
             Project: Apache Avro
          Issue Type: Improvement
          Components: java
    Affects Versions: 1.10.0
            Reporter: Novian Suryana
         Attachments: nullable_default_value.patch

When using ReflectData.AllowNull with defaultGenerated enabled to generate the schema for the following class:

 
{code:java}
  private static class WrappersWithDefault {
    Boolean aBoolean = Boolean.TRUE;
    Integer anInt = 1;
    Long aLong = 2L;
    Float aFloat = 3F;
    Double aDouble = 4D;
    PrimitivesWithDefault primitivesWithDefault = new PrimitivesWithDefault();
  }
{code}
it will attempt to generate default value as per the class definition but the avro type is set to ["null", "<type>"] which cause schema validation exception as it expect the default value to match the first type which is null.

Our solution is to override the ReflectData.createSchemaDefaultValue to always set default to null for nullable schema where null is the first type.

Would be good to have the patch incorporated in the next version so that we don't have to manually handle this particular scenario.

 

Cheers

Ian

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)