Skip to content

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

@axinger

Description

@axinger

问题描述

简要描述您碰到的问题。
序列化 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": {} 的嘛

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions