JSONObject
JSONObject.toJSONString(productInventory)
将实体对象转换成Json字符串时默认忽略值为null的属性。{"name":"sean","age":"12"}
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", null);
jsonObject.put("class", "12");
jsonObject.put("name", "");
// 使用默认序列化方式打印{"name":"","class":"12"}
System.out.println(jsonObject.toJSONString());
// 使用指定序列化方式 {"id":null,"name":"","class":"12"}
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
标签:12,name,jsonObject,Json,JSONObject,null
From: https://www.cnblogs.com/gogogofh/p/17101356.html