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

Generic API should require GenericEnumSymbol when writing Avro Enums

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.1
    • 1.8.0
    • None
    • None
    • Incompatible change
    • Hide
      Previous versions of Avro's Java library allowed String and Java Enum values to be used in the Generic API when writing fields that are Avro Enums. This change makes the Generic API strict by requiring GenericEnumSymbol instances. To ease updating downstream projects it also adds a constructor for GenericData.EnumSymbol that calls toString on a passed Object.
      Show
      Previous versions of Avro's Java library allowed String and Java Enum values to be used in the Generic API when writing fields that are Avro Enums. This change makes the Generic API strict by requiring GenericEnumSymbol instances. To ease updating downstream projects it also adds a constructor for GenericData.EnumSymbol that calls toString on a passed Object.

    Description

      I have a schema like:

      [
      {
        "type": "enum",
        "name": "Gender",
        "symbols": ["M", "F"]
      },
      
      {
        "type" : "record",
        "name" : "Foo",
        "fields" : [
          { "type" : ["Gender", "null"], "name" : "gender" },
          ...
        ]
      }
      ]
      

      I build a record like Foo foo = new Foo(); foo.gender = Gender.M;

      When I go to serialize this, I get:

      Not in union [{"type":"enum","name":"Gender","symbols":["M","F"]},"null"]: M
      	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:482)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:70)
      	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57)
      

      Attachments

        1. AVRO-997.permissive-generic-api.patch
          15 kB
          Sean Busbey
        2. AVRO-997.patch
          3 kB
          Doug Cutting
        3. AVRO-997.patch
          7 kB
          Sean Busbey
        4. AVRO-997.patch
          7 kB
          Sean Busbey

        Issue Links

          Activity

            People

              busbey Sean Busbey
              kimballa Aaron Kimball
              Votes:
              2 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: