You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by "Stephane L." <sl...@gmail.com> on 2009/10/28 00:25:42 UTC
GenericRecord and null value
For a project we are investigating using Avro as the format for
serializing/de-serializing data. I am currently testing with Avro 1.1.
I have been playing with GenericRecord and I have noticed that if I define a
schema and let's say for example one property is an array, I will get a
NullPointerException if at serialization time I did not put any data for
that particular field aka myRecord.get("array") --> return null.
So my question is : when using a GenericRecord is it mandatory that all
fields specified in the schema to be non null when serializiation is
happening ?
Stéphane
Re: GenericRecord and null value
Posted by Doug Cutting <cu...@apache.org>.
To permit null values you must use a union with null.
For example, if you want a field to be either an array of integers or
null, then its type should be:
["null", {"type": "array", "items": "int"}]
Doug
Stephane L. wrote:
> For a project we are investigating using Avro as the format for
> serializing/de-serializing data. I am currently testing with Avro 1.1.
>
> I have been playing with GenericRecord and I have noticed that if I
> define a schema and let's say for example one property is an array, I
> will get a NullPointerException if at serialization time I did not put
> any data for that particular field aka myRecord.get("array") --> return
> null.
>
> So my question is : when using a GenericRecord is it mandatory that all
> fields specified in the schema to be non null when serializiation is
> happening ?
>
> Stéphane