We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
使用 fastjson1 的 JSON.toJSON() 方法,转换后的数据中存在 com.alibaba.fastjson2.JSONArray 对象。
请填写以下信息:
如何操作可以重现该问题:
抛出异常,见日志输出。
import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; /** * JSON 处理方法 * * @author zhangrong * @date 2024/08/07 */ public class Test { public static void main(String[] args) { Map map1 = new HashMap(); List list1 = new LinkedList(); map1.put("list1", list1); Map map2 = new HashMap(); list1.add(map2); List list2 = new LinkedList(); map2.put("list2", list2); Map map3 = new HashMap(); list2.add(map3); List list3 = new LinkedList(); map3.put("list3", list3); list3.add("str1"); list3.add("str2"); list3.add("str3"); Object o1 = JSON.toJSON(map1); System.out.println(((JSONArray)((JSONObject)o1).get("list1")).get(0)); } }
使用 fastjson1 兼容 api 时,返回 fastjson1 的 JSONArray。
Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson2.JSONArray cannot be cast to com.alibaba.fastjson.JSONArray
The text was updated successfully, but these errors were encountered:
fix issue alibaba#2856, improve fastjson 1.x compatibility
dfa0810
fix issue #2856, improve fastjson 1.x compatibility
1094230
https://github.com/alibaba/fastjson2/releases/tag/2.0.53 问题已修复,请用新版本
Sorry, something went wrong.
No branches or pull requests
问题描述
使用 fastjson1 的 JSON.toJSON() 方法,转换后的数据中存在 com.alibaba.fastjson2.JSONArray 对象。
环境信息
请填写以下信息:
重现步骤
如何操作可以重现该问题:
抛出异常,见日志输出。
期待的正确结果
使用 fastjson1 兼容 api 时,返回 fastjson1 的 JSONArray。
相关日志输出
Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson2.JSONArray cannot be cast to com.alibaba.fastjson.JSONArray
The text was updated successfully, but these errors were encountered: