You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Youssef Hatem <yo...@rwth-aachen.de> on 2013/10/11 18:24:00 UTC
Default encapsulation of strings fields into unions
Hi,
Assume I have the following schema:
{
"name": "Foo",
"type":"record",
"fields":[ {"name": "Bar", "type":"string"} ]
}
Since a string can be null, will Avro (Java implementation) encapsulate Bar in a union? (i.e. type of Bar field will be regarded as ["null", "string"]).
I am almost certain that it should not because it will lead to inconsistencies with encoding/decoding but I want to make sure.
Another question, what happens when we want to deserialize a null string?
Best regards,
Youssef Hatem
Re: Default encapsulation of strings fields into unions
Posted by Doug Cutting <cu...@apache.org>.
On Fri, Oct 11, 2013 at 9:24 AM, Youssef Hatem
<yo...@rwth-aachen.de> wrote:
> Since a string can be null, will Avro (Java implementation) encapsulate Bar in a union? (i.e. type of Bar field will be regarded as ["null", "string"]).
If you want to intermix nulls and strings then you need to explicitly
use a union. If null is passed as a string then a
NullPointerException is thrown.
> Another question, what happens when we want to deserialize a null string?
A serialized string is never null. It may be an empty string.
Doug