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]AutoType long类型解析成Integer #2608

Closed
zhxing opened this issue May 21, 2024 · 2 comments
Closed

[BUG]AutoType long类型解析成Integer #2608

zhxing opened this issue May 21, 2024 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@zhxing
Copy link

zhxing commented May 21, 2024

问题描述

简要描述您碰到的问题。
AutoType long类型解析成Integer,请看代码

环境信息

请填写以下信息:

  • OS信息: [e.g.:windows ]
  • JDK信息: [e.g.:Openjdk 1.8.0_221]
  • 版本信息:[e.g.:Fastjson2 2.0.49]

重现步骤

如何操作可以重现该问题:
执行代码

    @Test
    public void testLong() {
        String str = "[300000000L]";
        List list = JSONObject.parseObject(str, List.class, Feature.SupportAutoType);
        System.out.println(list.get(0).getClass());//print class java.lang.Integer
        Assert.assertTrue(list.get(0).getClass() == Long.class);
    }

期待的正确结果

正确解析成long类型

相关日志输出

print class java.lang.Integer
java.lang.AssertionError

附加信息

建议修改的地方:com.alibaba.fastjson2.JSONReaderUTF16 的4038行

        if (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S') {
            if (!intOverflow) {//这里改成 if (!intOverflow||ch == 'L' ) ,long类型不存在溢出的问题
                switch (ch) {
                    case 'B':
                        valueType = JSON_TYPE_INT8;
                        break;
                    case 'S':
@zhxing zhxing added the bug Something isn't working label May 21, 2024
@wenshao wenshao added this to the 2.0.51 milestone May 21, 2024
@wenshao wenshao added the fixed label May 21, 2024
@wenshao
Copy link
Member

wenshao commented May 21, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/
问题已修复,请帮忙用2.0.51-SNAPSHOT版本验证

@wenshao
Copy link
Member

wenshao commented Jun 1, 2024

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

@wenshao wenshao closed this as completed Jun 1, 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