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]2.0.53 JSONObject ClassCastException。使用 fastjson1 的 JSON.toJSON() 方法,转换后的数据中存在 com.alibaba.fastjson2.JSONObject对象。 #3185

Open
happywbl opened this issue Nov 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@happywbl
Copy link

问题描述
使用 fastjson1 的 JSON.toJSON() 方法,转换后的数据中存在 com.alibaba.fastjson2.JSONObject 对象。

环境信息
请填写以下信息:

OS信息:Windows 10
JDK信息:JDK信息:Oracle Java 1.8.0_381
版本信息:Fastjson2 2.0.53
重现步骤
如何操作可以重现该问题:

抛出异常,见日志输出。
`

    Map map1 = new HashMap();

    List list1 = new LinkedList();
    map1.put("list1", list1);

    Map map2 = new HashMap();
    list1.add(map2);

    map2.put("id", "123");
    map2.put("name", "张三");


    JSONObject o1 = (JSONObject)JSON.toJSON(map1);

    JSONArray jsonArray = (JSONArray) o1.get("list1");

    for (Object subJsonObject : jsonArray) {
       JSONObject jsonObject = (JSONObject) subJsonObject;
    }

`
期待的正确结果
使用 fastjson1 兼容 api 时,返回 fastjson1 的 JSONObject 。

相关日志输出
Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson2.JSONObject cannot be cast to com.alibaba.fastjson.JSONObject

@happywbl happywbl added the bug Something isn't working label Nov 28, 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
Projects
None yet
Development

No branches or pull requests

1 participant