Open DaveSanders opened 8 years ago
A quick note, if I do object.service_code.equals("WDI"), then it does evaluate true. So my immediate issue is solved. But I'm still curious why these null characters happen.
Could you provide a test case?
I'll do not have a SSCCE either but i am seeing the same nul bytes generated sometimes. Its even more worse - they are after "each" character. So having e.g. a property "login" in the object this becomes that in the string (it applies to anything in the string which is generated, properties, structure code, values etc.):
l\u0000o\u0000g\u0000i\u0000n\u0000
Any ideas where in the gson code this could happen so i can debug it there to get an idea about the cause and a possible fix @swankjesse ?
Dear Gson team, this happens intermittently. So far we are unable to reproduce it.
This issue originally came up when I first reported it on the orhanobut/wasp library, and that issue contains specific examples and screenshots:
https://github.com/orhanobut/wasp/issues/145
While debugging Wasp to solve this, it turns out its gson.fromJson that is creating these strings. Basically when a bit of json like this:
{"service_code:"WDI"}
is deserialized into my object, the value that is put into the string is:
WDI\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000
Making comparisons such as this, not true:
object.service_code == "WDI" // => false
Is this a serialization issue with gson? Is it a memory thing of some sort? (I also saw an empty string get serialized with what looks to be other data.) Or is there some sort of builder setting I am not invoking to do this properly? The code that does the initialization of gson, and the fromJson is pretty drop dead simple:
new Gson()
return gson.fromJson(content, type);