Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

WriteNullStringAsEmpty和WriteMapNullValue 两个序列化属性不能同时生效 #4507

Open
lenber opened this issue May 7, 2024 · 0 comments

Comments

@lenber
Copy link

lenber commented May 7, 2024

问题:WriteNullStringAsEmpty和WriteMapNullValue 两个序列化属性不能同时生效

实例代码:

public static void main(String[] args) {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("a", 1);
        jsonMap.put("b", "");
        jsonMap.put("c", null);
        jsonMap.put("d", "哈哈");

        String str = JSONObject.toJSONString(jsonMap, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteMapNullValue);
        System.out.println(str);
}

输出结果:
{"a":1,"b":"","c":null,"d":"哈哈"}

期望结果:
{"a":1,"b":"","c":"","d":"哈哈"}

版本:
1.2.83

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant