Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2959

Set default to null for nullable when defaultGenerated is enabled in ReflectData

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.10.0
    • None
    • java
    • None

    Description

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

       

        private static class WrappersWithDefault {
          Boolean aBoolean = Boolean.TRUE;
          Integer anInt = 1;
          Long aLong = 2L;
          Float aFloat = 3F;
          Double aDouble = 4D;
          PrimitivesWithDefault primitivesWithDefault = new PrimitivesWithDefault();
        }
      

      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

       

      Attachments

        1. nullable_default_value.patch
          4 kB
          Novian Suryana

        Activity

          People

            Unassigned Unassigned
            nsuryana Novian Suryana
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: