Solve null lost on the turn json problem

1. loss of effect

 public static void main(String[] args) {
        User user = new User();
        Map<String, Object> reMap = new HashMap<String, Object>();
        reMap.put("aaa",null);
        reMap.put("bbb",user);
        String json = JSONObject.toJSONString(reMap);
        System.out.println(json);
    }

Here Insert Picture Description
2.不丢失效果(SerializerFeature.WriteMapNullValue)(SerializerFeature.WRITE_MAP_NULL_FEATURES)

 public static void main(String[] args) {
        User user = new User();
        Map<String, Object> reMap = new HashMap<String, Object>();
        reMap.put("aaa",null);
        reMap.put("bbb",user);
        String json = JSONObject.toJSONString(reMap,SerializerFeature.WriteMapNullValue);
        String json1 = JSONObject.toJSONString(reMap,SerializerFeature.WRITE_MAP_NULL_FEATURES);
        System.out.println("json:"+json);
        System.out.println("json1:"+json1);
    }

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/WXN069/article/details/91981542