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]从String反序列化到BigDecimal转换不正确,正数变为负数 #540

Closed
LinZhenli opened this issue Jul 9, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@LinZhenli
Copy link

LinZhenli commented Jul 9, 2022

问题描述:

[Integer.MAX_VALUE+3L, Integer.MAX_VALUE*2L+1]该区间的数,从String反序列化到BigDecimal转换不正确,正数变为负数。
2.0.8版本有这个问题。但测试了fastjson1.2.76是没问题的。

测试代码:

public class TestJson {
    public static void main(String[] args) {
        A a = new A();
        a.num=Integer.MAX_VALUE+3L+"";
        B b = JSONObject.parseObject(JSONObject.toJSONString(a), B.class);
        System.out.println(a.num);
        System.out.println(b.num);
    }
}

@Data
class A{
    String num;
}
@Data
class B{
    BigDecimal num;
}

期待的正确结果

2147483650
2147483650

相关日志输出

2147483650
-2147483646

@LinZhenli LinZhenli added the bug Something isn't working label Jul 9, 2022
@LinZhenli
Copy link
Author

修改问题格式

wenshao added a commit that referenced this issue Jul 9, 2022
@wenshao wenshao added this to the 2.0.9 milestone Jul 9, 2022
wenshao added a commit that referenced this issue Jul 10, 2022
@wenshao
Copy link
Member

wenshao commented Jul 10, 2022

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

@wenshao wenshao closed this as completed Jul 10, 2022
@chenzhongyu11
Copy link

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

这个问题是我发现的,数据也是我的

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

3 participants