fastjson version 1.2.12 WriteNullStringAsEmpty 规则不生效

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

public class Test {
public static void main(String[] args) {

TestModel testModel = new TestModel();
    testModel.setDesc(null);

    System.out.println(JSON.toJSONString(testModel, SerializerFeature.WriteNullStringAsEmpty));
}

static class TestModel {
    String desc;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}

}

实验输出结果为:{}

slwdgvem

slwdgvem1#

之前需要结合WriteMapNullValue才能生效,升级到最新版本吧,比如1.2.30就好了

相关问题