Skip to content
New issue

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

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

Already on GitHub? # to your account

JSONWriter.Feature.NullAsDefaultValue "map": null #372

Closed
axinger opened this issue May 28, 2022 · 4 comments
Closed

JSONWriter.Feature.NullAsDefaultValue "map": null #372

axinger opened this issue May 28, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@axinger
Copy link

axinger commented May 28, 2022

问题描述

简要描述您碰到的问题。
序列化 map 还是为null
config.setWriterFeatures( JSONWriter.Feature.NullAsDefaultValue)
map返回为null "map": null,

环境信息

请填写以下信息:

springboot 2.6.3

  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.4]
    @Bean
    public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {

        FastJsonHttpMessageConverter messageConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig config = messageConverter.getFastJsonConfig();

        config.setReaderFeatures(JSONReader.Feature.FieldBased, JSONReader.Feature.SupportArrayToBean);
        config.setDateFormat("yyyy-MM-dd HH:mm:ss");
        config.setWriterFeatures(
                JSONWriter.Feature.PrettyFormat
                , JSONWriter.Feature.NullAsDefaultValue

        );
        messageConverter.setFastJsonConfig(config);
        messageConverter.setDefaultCharset(StandardCharsets.UTF_8);
        messageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));

        return messageConverter;

    }

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。
不应该为 "map": {} 的嘛

@axinger axinger added the bug Something isn't working label May 28, 2022
@wenshao
Copy link
Member

wenshao commented May 28, 2022

现在当存在NullAsDefaultValue是,WriteNulls值是自动生效的

@axinger axinger changed the title [BUG] JSONWriter.Feature.NullAsDefaultValue "map": null May 30, 2022
@axinger
Copy link
Author

axinger commented May 30, 2022

@wenshao WriteNulls值是自动生效的 , 那map为空时,输出 "map": null, 和 "map": {} 哪个是预期值呢?

@wenshao wenshao added this to the 2.0.6 milestone Jun 1, 2022
wenshao added a commit that referenced this issue Jun 2, 2022
@wenshao
Copy link
Member

wenshao commented Jun 2, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/

问题已经修复,请帮忙用2.0.6-SNAPSHOT版本验证,2.0.6正式版预计6月5日前发布

@wenshao
Copy link
Member

wenshao commented Jun 4, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.6
问题已经修复,请用新版本

@wenshao wenshao closed this as completed Jun 4, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants