Closed wdollar closed 2 months ago
在部分字段上使用@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls)注解,序列化时无法正常序列化null值。
@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls)
代码如下
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.annotation.JSONField; import lombok.Data; @Data public class C { @JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) private Long l; @JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) private Double d; @JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) private Integer i; @JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) private String s; public static void main(String[] args) { System.out.println(JSON.toJSONString(new C())); } }
输出结果
{"i":null,"s":null}
{"l":null,"d":null,"i":null,"s":null}
无
https://github.com/alibaba/fastjson2/releases/tag/2.0.53 问题已修复,请用新版本
问题描述
在部分字段上使用
@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls)
注解,序列化时无法正常序列化null值。环境信息
重现步骤
代码如下
输出结果
期待的正确结果
相关日志输出
无
附加信息
无