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

反馈问题:当 Double 字段为 null时。开启 WriteNullNumberAsZero 和 WriteLongAsString,会变成 "0" #2211

Closed
noear opened this issue Jan 23, 2024 · 7 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@noear
Copy link
Contributor

noear commented Jan 23, 2024

复现代码:

  • 定义个实体类
@Getter
@Setter
public class UserDo implements Serializable {
    String s0;

    String s1 = "noear";

    Boolean b0;
    boolean b1 = true;

    Long n0;
    Long n1 = 1L;

    Double d0;
    Double d1 = 1.0D;

    Object obj0;
    List list0;
    Map map0;
    Map map1;
}
  • 序列化
UserDo userDo = new UserDo();
        String json = JSON.toJSONString(userDo, JSONWriter.Feature.WriteNullNumberAsZero, JSONWriter.Feature.WriteLongAsString);
        System.out.println(json);
  • 打印出来的字符串为:
{"b1":true,"d0":"0","d1":1.0,"n0":"0","n1":"1","s1":"noear"}

其中 d1 变成了字符串 "0"。d1 是double 。应该不受 WriteLongAsString 的影响。

@noear noear added the bug Something isn't working label Jan 23, 2024
@wenshao wenshao added this to the 2.0.46 milestone Jan 24, 2024
@wenshao
Copy link
Member

wenshao commented Jan 24, 2024

你是不是可以使用BrowserCompatible ?

@wenshao
Copy link
Member

wenshao commented Jan 24, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.46-SNAPSHOT/
问题已修复,请帮忙用2.0.46-SNAPSHOT版本验证,正式版本预计在3月初发布。

@noear
Copy link
Contributor Author

noear commented Jan 24, 2024

能不能早点发啊。这个影响大呀:)

@wenshao
Copy link
Member

wenshao commented Jan 24, 2024

这个周末(28日)可以么?

@noear
Copy link
Contributor Author

noear commented Jan 24, 2024

好:)。。。你发完,我跟着发个 solon ,正好把 fastjosn 升掉:)。。。最好你早上发,我下午发:)

wenshao added a commit that referenced this issue Jan 27, 2024
@noear
Copy link
Contributor Author

noear commented Jan 27, 2024

2.0.46-SNAPSHOT 试过了,OK!

@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

@wenshao wenshao closed this as completed Jan 29, 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

2 participants