You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Sean Busbey (JIRA)" <ji...@apache.org> on 2014/10/03 23:20:34 UTC

[jira] [Updated] (AVRO-997) Generic API should require GenericEnumSymbol when writing Avro Enums

     [ https://issues.apache.org/jira/browse/AVRO-997?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sean Busbey updated AVRO-997:
-----------------------------
    Release Note: 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.
         Summary: Generic API should require GenericEnumSymbol when writing Avro Enums  (was: Union of enum and null cannot be serialized)

Updated subject to reflect the change that happened. Also added a release note since this is an incompatible change.

> Generic API should require GenericEnumSymbol when writing Avro Enums
> --------------------------------------------------------------------
>
>                 Key: AVRO-997
>                 URL: https://issues.apache.org/jira/browse/AVRO-997
>             Project: Avro
>          Issue Type: Bug
>    Affects Versions: 1.5.1
>            Reporter: Aaron Kimball
>            Assignee: Sean Busbey
>             Fix For: 1.8.0
>
>         Attachments: AVRO-997.patch, AVRO-997.patch, AVRO-997.patch, AVRO-997.permissive-generic-api.patch
>
>
> I have a schema like:
> {code}
> [
> {
>   "type": "enum",
>   "name": "Gender",
>   "symbols": ["M", "F"]
> },
> {
>   "type" : "record",
>   "name" : "Foo",
>   "fields" : [
>     { "type" : ["Gender", "null"], "name" : "gender" },
>     ...
>   ]
> }
> ]
> {code}
> I build a record like {{Foo foo = new Foo(); foo.gender = Gender.M;}}
> When I go to serialize this, I get:
> {code}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)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)