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导致Long、Double字段序列化为null #3049

Open
wdollar opened this issue Oct 8, 2024 · 0 comments
Open

[BUG]WriteNulls导致Long、Double字段序列化为null #3049

wdollar opened this issue Oct 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wdollar
Copy link

wdollar commented Oct 8, 2024

问题描述

使用注解@JSONField(serializeFeatures = {JSONWriter.Feature.WriteNulls})的Long、Double字段在序列化时无论是否有值均输出为null。内部类不受影响。

环境信息

  • OS信息: Win11 23H2 22631.4249
  • JDK信息:Eclipse Adoptium Temurin-17.0.12+7
  • 版本信息:Fastjson2 2.0.53

重现步骤

代码

public class Main {
    public static void main(String[] args) {
        Clazz c = new Clazz();
        c.setD(1D);
        System.out.println(JSON.toJSONString(c));

        InnerClazz ic = new InnerClazz();
        ic.setD(1D);
        System.out.println(JSON.toJSONString(ic));
    }

    static class InnerClazz {
        @JSONField(serializeFeatures = {JSONWriter.Feature.WriteNulls})
        private Double d;

        public Double getD() { return d; }
        public void setD(Double d) { this.d = d; }
    }
}

public class Clazz {
    @JSONField(serializeFeatures = {JSONWriter.Feature.WriteNulls})
    private Double d;

    public Double getD() { return d; }
    public void setD(Double d) { this.d = d; }
}

输出为

{"d":null}
{"d":1.0}

期待的正确结果

{"d":1.0}
{"d":1.0}

相关日志输出

(无)

附加信息

(无)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant