Closed GoogleCodeExporter closed 9 years ago
Test Code: HashMap<String, Object> hs = new HashMap<String, Object>(); HashMap<String, Object> details = new HashMap<String, Object>(); hs.put("id", 12); hs.put("name", "Alejandro"); hs.put("details", details); Boolean includeNullFields = true; Boolean prettyRender = true; try { GsonBuilder gsonBuilder = new GsonBuilder(); if (includeNullFields && prettyRender) gsonBuilder.serializeNulls().setPrettyPrinting(); else if (includeNullFields && !prettyRender) gsonBuilder.serializeNulls(); else if (!includeNullFields && prettyRender) gsonBuilder.setPrettyPrinting(); Gson gson = null; gson = gsonBuilder.create(); String jsonResponse = gson.toJson(hs); System.out.println(jsonResponse); } catch (Exception e) { e.printStackTrace(); } The above code outputs: {"id":12,"details":{}"name":"Alejandro"} If Pretty Printing is NOT used then the output is correct: {"id":12,"details":{},"name":"Alejandro"}
Original issue reported on code.google.com by bobghera...@gmail.com on 21 Apr 2010 at 10:09
bobghera...@gmail.com
The code in SVN works. I checked in a test case with r593.
Original comment by limpbizkit on 3 Sep 2010 at 6:45
limpbizkit
Original issue reported on code.google.com by
bobghera...@gmail.com
on 21 Apr 2010 at 10:09