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]JSONArray toJavaList Exception #255

Closed
MisakaTAT opened this issue May 15, 2022 · 4 comments
Closed

[BUG]JSONArray toJavaList Exception #255

MisakaTAT opened this issue May 15, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@MisakaTAT
Copy link

问题描述

JSONArray 直接调用 toJavaList 方法抛出如下异常:
Exception in thread "main" com.alibaba.fastjson2.JSONException: can not convert from class java.lang.String to class java.lang.String

环境信息

  • OS信息: [e.g.:Windows10 21H2 19044.1706]
  • JDK信息: [e.g.:Openjdk 1.8]
  • 版本信息:[e.g.:Fastjson2 2.0.3]

重现步骤

    @Data
    public static class TestBean {
        private String type;
        private Map<String, String> data;
    }

    public static void main(String[] args) {
        JSONArray array = new JSONArray();
        array.add(new JSONObject() {{
            put("type", "text");
            put("data", new JSONObject() {{
                put("content", "hello111");
            }});
        }});
        array.add(new JSONObject() {{
            put("type", "text");
            put("data", new JSONObject() {{
                put("content", "hello222");
            }});
        }});
        // Exception in thread "main" com.alibaba.fastjson2.JSONException: can not convert from class java.lang.String to class java.lang.String
        System.out.println(array.toJavaList(TestBean.class));

        // [Test.TestBean(type=text, data={content=hello111}), Test.TestBean(type=text, data={content=hello222})]
        System.out.println(JSON.parseArray(array.toJSONString(), TestBean.class));
    }

期待的正确结果

调用 toJavaList 可正常转换

相关日志输出

com.alibaba.fastjson2.JSONException: can not convert from class java.lang.String to class java.lang.String

	at com.alibaba.fastjson2.reader.ObjectReaderImplMapTyped.createInstance(ObjectReaderImplMapTyped.java:69)
	at com.alibaba.fastjson2.JSONObject.toJavaObject(JSONObject.java:1012)
	at com.alibaba.fastjson2.reader.ObjectReader.createInstance(ObjectReader.java:114)

附加信息

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

@MisakaTAT MisakaTAT added the bug Something isn't working label May 15, 2022
@MisakaTAT
Copy link
Author

在v1版本中无此问题

@wenshao wenshao added this to the 2.0.4 milestone May 15, 2022
wenshao added a commit that referenced this issue May 15, 2022
@wenshao
Copy link
Member

wenshao commented May 15, 2022

谢谢反馈,问题已经重现并修复,你可以用2.0.4-SNAPSHOT 快照版本验证, 2.0.4预计发布日期在22日

@MisakaTAT
Copy link
Author

2.0.4-SNAPSHOT 经验证已无法复现此问题,感谢!

@wenshao
Copy link
Member

wenshao commented May 21, 2022

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

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

2 participants