programing tip

값이 null 인 맵 항목을 무시하는 Gson

itbloger 2020. 7. 12. 10:13
반응형

값이 null 인 맵 항목을 무시하는 Gson


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}

모든 항목을 포함 시키려면 어떻게해야합니까?


http://sites.google.com/site/gson/gson-user-guide#TOC-Null-Object-Support를 참조 하십시오 .

Gson gson = new GsonBuilder().serializeNulls().create();

참고 URL : https://stackoverflow.com/questions/3923759/gson-ignoring-map-entries-with-value-null

반응형