vagrant1991 / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Smart quotes are treated incorrectly #598

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a string that uses smart quotes around the key or value or both in a 
JSON element
2. Have GSON parse it into a map
3. Have GSON turn it back into JSON

What is the expected output? What do you see instead?
GSON treats the smart quotes as part of the key or value.  GSON should not 
consider this valid JSON at all.  Jsonlint.com does not, Chrome does not.

Please provide any additional information below.

In Java use a string like this:

private static final String badJson = " { “ipAddress” : “192.168.1.100” 
}";

Smart quotes are sround ipAddress and 192.168.1.100, those are not regular 
quotes.

Then do this:

Gson gson = new Gson();
Map<String, String> map;
map = gson.fromJson(json, Map.class);
System.out.println(name + gson.toJson(map));

Gson will print this:

{"“ipAddress”":"“192.168.1.100”"}

Original issue reported on code.google.com by t...@mattison.org on 19 Sep 2014 at 10:53