discomarathon / google-gson

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

Map Keys are not escaped correctly if they contain " #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Map<String,String> s = new HashMap<String, String>();
s.put("h\"allo", "w\"elt");
s.put("hallo", "welt");

Writer w = new PrintWriter(System.out, true);
gson.toJson(s, w);
w.flush();      

prints (invalid JSON):
{"h"allo":"w\"elt","hallo":"welt"}

But should be 
{"h\"allo":"w\"elt","hallo":"welt"}

Original issue reported on code.google.com by developm...@mj-networks-gmbh.de on 22 Nov 2009 at 6:16

GoogleCodeExporter commented 9 years ago
Unfortunaly just copy&paste the default MapTypeAdapter code doesnt work, since 
all
important classes are gson package-visible only 
e.g. TypeInfoMap, JsonDeserializationContextDefault

Original comment by developm...@mj-networks-gmbh.de on 22 Nov 2009 at 6:32

GoogleCodeExporter commented 9 years ago
Is there any solution/quick fix for this issue?

Original comment by marek.ho...@gmail.com on 14 Jun 2010 at 11:06

GoogleCodeExporter commented 9 years ago
This could be fixed by using JsonWriter in gson.toJson().

Original comment by limpbizkit on 20 Aug 2010 at 5:33

GoogleCodeExporter commented 9 years ago
Issue 180 has been merged into this issue.

Original comment by limpbizkit on 20 Aug 2010 at 5:34

GoogleCodeExporter commented 9 years ago
Issue 182 has been merged into this issue.

Original comment by limpbizkit on 20 Aug 2010 at 5:35

GoogleCodeExporter commented 9 years ago
I checked in failing test cases for this problem as it appears in both map keys 
(r572) and object property names (r573).

Original comment by limpbizkit on 20 Aug 2010 at 5:47

GoogleCodeExporter commented 9 years ago
Fix with r577.

Original comment by joel.leitch@gmail.com on 21 Aug 2010 at 6:51