Hi John, Thanks for the link. I understood now. So that means we should check for the object as null and if it is not null then convert back to string? Is this the right way then? Or there is any better way by which we can extract all the typed value from GenericRecord? Below is the question I had long time back but everyone suggested directly to use "String.valueOf".
http://stackoverflow.com/questions/40792614/how-to-get-typed-value-from-genericrecord On Fri, Dec 16, 2016 at 6:02 PM, John McClean <[email protected]> wrote: > 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 <[email protected]> > 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? >> >> >
