fastjson 默认配置 空JSON put value为null的对象后 isEmpty 返回false KeySet不为空

s6fujrry  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(272)

ver1.2.58
默认配置下 value为null的项 不展示到JSONString
空JSON put value为null的对象后 isEmpty 返回false KeySet不为空
让人很困扰

gudnpqoy

gudnpqoy1#

JSONObject j = JSONObject.parseObject("{}");
        j.put("3", null);
        System.out.println(j.keySet());
        System.out.println(j.size());

I tried like this. It seems happen what you said.
But JSONObject is implements from Map.
You problem is why Map allows put data like ("3", null).
I suggest to use Map.containsValue(null) to check null-value.

相关问题