Question

Gson gson = new Gson();

Map<String,Object> map = new HashMap<String, Object>();
map.put("a", 1);
map.put("b", null);

System.out.println(gson.toJson(map)); //prints {"a":1}

How do I get it to include all entries?

Was it helpful?

Solution

See http://sites.google.com/site/gson/gson-user-guide#TOC-Null-Object-Support:

Gson gson = new GsonBuilder().serializeNulls().create();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top