Frage

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}

Wie bekomme ich es alle Einträge enthalten?

War es hilfreich?

Lösung

Siehe http://sites.google .com / site / Gson / Gson-user-Führer # TOC-Null-Objekt-Unterstützung :

Gson gson = new GsonBuilder().serializeNulls().create();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top