This isn't an avro issue, it's to do with your use of 'valueOf'. You need
to check for null before you call it. More info's here.

http://stackoverflow.com/questions/13577892/what-is-difference-between-null-and-null-of-string-valueofstring-object

J

On Fri, Dec 16, 2016 at 5:54 PM, Check Peck <comptechge...@gmail.com> wrote:

> I am working with Avro and in my avro schema I have one field like this:
>
>      {
>         "name" : "userId",
>         "type" : [ "null", "string" ],
>         "doc" : "some doc"
>       },
>
> This is how I am extracting userId field from GenericRecord:
>
>     GenericRecord payload = decoder.decode(record.value());
>     String userid = String.valueOf(payload.get("userId"));
>     // sometimes userid comes as null string meaning like this "null"
>     System.out.println(Strings.isNullOrEmpty(userid));
>
> And because of that "null" string, my sysout prints out as false.  Is
> there any way to extract userid as null instead of "null" String?
>
> Bcoz when I check for null string it fails and if I have to accommodate
> this fix, I have to add extra check with ".equals" which I want to avoid if
> possible? Is there any way?
>
>

Reply via email to