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

[BUG]WriteNulls序列化时丢失部分null值字段 #2952

Closed
wdollar opened this issue Sep 10, 2024 · 1 comment
Closed

[BUG]WriteNulls序列化时丢失部分null值字段 #2952

wdollar opened this issue Sep 10, 2024 · 1 comment
Labels
bug Something isn't working fixed
Milestone

Comments

@wdollar
Copy link

wdollar commented Sep 10, 2024

问题描述

在部分字段上使用@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls)注解,序列化时无法正常序列化null值。

环境信息

  • OS信息: Windows 11 中文版 23H2 22631.4112
  • JDK信息:Temurin-17.0.12+7
  • 版本信息:Fastjson2 2.0.52

重现步骤

代码如下

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}

相关日志输出

附加信息

@wdollar wdollar added the bug Something isn't working label Sep 10, 2024
@yanxutao89 yanxutao89 self-assigned this Sep 11, 2024
yanxutao89 added a commit that referenced this issue Sep 11, 2024
…iledWriter.features is not among (0, JSONWriter.Feature.FieldBased.mask, FieldInfo.FIELD_MASK), for issue #2952
@wenshao wenshao added this to the 2.0.53 milestone Sep 15, 2024
@wenshao wenshao added the fixed label Sep 15, 2024
@yanxutao89 yanxutao89 removed their assignment Sep 15, 2024
@wenshao
Copy link
Member

wenshao commented Sep 16, 2024

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

@wenshao wenshao closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants