google / google/gson

Null characters (\u0000) in strings?

Open
#906 4 comments 0 reactions 0 assignees View on GitHub
needs-info
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

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);`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.