Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant