Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG]JSON.toJavaObject与上一大版本不兼容 #854

Closed
Alennai opened this issue Oct 20, 2022 · 3 comments
Closed

[BUG]JSON.toJavaObject与上一大版本不兼容 #854

Alennai opened this issue Oct 20, 2022 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@Alennai
Copy link

Alennai commented Oct 20, 2022

问题描述

fastjson 版本由1.2.83 升级到2.0.12,原json字符串中Integer类型可以转换boolean类型对象,现在转换异常

环境信息

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.12]

重现步骤

如何操作可以重现该问题:
String str = "{"test":1}";
JSON.toJavaObject(JSON.parseObject(str),
Test.class);

  1. 使用JSON.toJavaObject方法
  2. 输入 "{\"test\":1}" 数据
  3. 出现如下错误
    Exception in thread "main" com.alibaba.fastjson2.JSONException: can not cast to java.lang.Boolean, from class java.lang.Integer
    at com.alibaba.fastjson2.util.TypeUtils.cast(TypeUtils.java:244)
    at com.alibaba.fastjson2.reader.ObjectReader.createInstance(ObjectReader.java:111)
    at com.alibaba.fastjson.JSONObject.toJavaObject(JSONObject.java:996)
    at com.alibaba.fastjson.JSON.toJavaObject(JSON.java:1212)
String str = "{\"test\":1}";
JSON.toJavaObject(JSON.parseObject(str),
            Test.class);

期待的正确结果

期待兼容上一版本

相关日志输出

Exception in thread "main" com.alibaba.fastjson2.JSONException: can not cast to java.lang.Boolean, from class java.lang.Integer
at com.alibaba.fastjson2.util.TypeUtils.cast(TypeUtils.java:244)
at com.alibaba.fastjson2.reader.ObjectReader.createInstance(ObjectReader.java:111)
at com.alibaba.fastjson.JSONObject.toJavaObject(JSONObject.java:996)
at com.alibaba.fastjson.JSON.toJavaObject(JSON.java:1212)

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@Alennai Alennai added the bug Something isn't working label Oct 20, 2022
@Alennai Alennai changed the title [BUG] [BUG]JSON.toJavaObject与上一大版本不兼容 Oct 20, 2022
@ishu-thakur
Copy link

Hi @Alennai sorry I quite didn't understand the language so I wanted to ask and clarify are you getting exception when you are trying to cast string to JSON ?

@wenshao
Copy link
Member

wenshao commented Oct 20, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.16-SNAPSHOT/
问题已经修复,请用2.0.16-SNAPSHOT帮忙验证,2.0.16版本预计在10月30日前发布

@wenshao wenshao added this to the 2.0.16 milestone Oct 20, 2022
@wenshao wenshao added the fixed label Oct 21, 2022
@wenshao
Copy link
Member

wenshao commented Oct 22, 2022

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

@wenshao wenshao closed this as completed Oct 22, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants