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}

Comment puis-je obtenir pour inclure toutes les entrées?

Était-ce utile?

La solution

Voir http://sites.google .com / site / gson / gson-Guide utilisateur # TOC-Null-objet-support :

Gson gson = new GsonBuilder().serializeNulls().create();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top