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

Aaron Kimball commented on AVRO-997:
------------------------------------

Doug, I'm using Avro 1.5.1 as noted in the affectsVersion field of this ticket.

Scott, you're correct: our system uses a single codepath to serialize all 
values passed in from the client/data layer to the underlying storage. This 
codepath accepts generic and specific values, and we currently always allocate 
a GenericDatumWriter for each schema. At least until this particular schema, 
this has always worked.

Is this an illegal use of GenericDatumWriter? If so, maybe its write() method 
could warn (or more strongly, throw an exception) if an instance of 
SpecificRecord is passed as an argument?
                
> Union of enum and null cannot be serialized
> -------------------------------------------
>
>                 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
>
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to