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

fastjson1支持返回的泛型的DTO转成List,fastjson2不支持 #1291

Closed
hcxxiaomo opened this issue Mar 27, 2023 · 1 comment
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@hcxxiaomo
Copy link
Contributor

###fastjson1支持返回的泛型的DTO转成List,fastjson2不支持
fastjson1和2数据返回兼容不同
温少好,跟 #1240 类似,又发现另一个fastjson1的兼容性问题

环境信息

请填写以下信息:

  • OS信息: windows 16G
  • JDK信息:Openjdk 1.8.0_291
  • 版本信息:Fastjson2 2.0.27

重现步骤

代码如下

        String info = "{\"obj\":{\"unitCode\":\"955H\"}}";
        Result<List<String>> listResult = com.alibaba.fastjson.JSON.parseObject(info, new com.alibaba.fastjson.TypeReference<Result<List<String>>>() {});
        System.out.println(listResult.obj);
        System.out.println(listResult.obj.get(0));


        listResult = com.alibaba.fastjson2.JSON.parseObject(info, new com.alibaba.fastjson2.TypeReference<Result<List<String>>>() {});
        System.out.println(listResult.obj);
        System.out.println(listResult.obj.get(0));

期待的正确结果

上面fastjson1的,能正常解析,但是下面fastjson2的,就会报错

相关日志输出

com.alibaba.fastjson2.JSONException: offset 8, character {, line 1, column 9, fastjson-version 2.0.26 {"obj":{"unitCode":"955H"}}

at com.alibaba.fastjson2.reader.ObjectReaderImplListStr.readObject(ObjectReaderImplListStr.java:181)
at com.alibaba.fastjson2.reader.ORG_1_1_Result.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:786)
at com.xiaomo.maven.cha.com.xiaomo.study.enums.reflect.JsonTest.test1(JsonTest.java:26)
@hcxxiaomo hcxxiaomo added the bug Something isn't working label Mar 27, 2023
hcxxiaomo added a commit to hcxxiaomo/fastjson2 that referenced this issue Mar 27, 2023
hcxxiaomo added a commit to hcxxiaomo/fastjson2 that referenced this issue Mar 28, 2023
wenshao pushed a commit that referenced this issue Mar 28, 2023
* improved fastjson 1.x compatible, for issues #1291
@wenshao wenshao added this to the 2.0.27 milestone Mar 30, 2023
@wenshao wenshao added the fixed label Mar 30, 2023
@wenshao
Copy link
Member

wenshao commented Apr 8, 2023

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

@wenshao wenshao closed this as completed Apr 8, 2023
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