Json类型转换异常

复制代码
class com.alibaba.fastjson.JSONObject cannot be cast to class com.xxx.xxOrder (com.alibaba.fastjson.JSONObject and com.xxx.xxOrder are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @25b5c5e3

大概率是因为 JSON.parseObject(a,A.class) 中 A 为泛型类,该代码执行一次,会导致JSON内部参数变化,导致其他地方调用 JSON.parseObject(a,B.class) 失败,其中B是非泛型类。

JSON.parseObject 不能转换泛型类,可以先获取 JSONObject 对象,再用key获取数据转换。

相关推荐
huohaiyu4 分钟前
synchronized (Java)
java·开发语言·安全·synchronized
梵得儿SHI4 分钟前
Java 工具类详解:Arrays、Collections、Objects 一篇通关
java·工具类·collections·arrays·objects
熊小猿11 分钟前
Spring Boot 的 7 大核心优势
java·spring boot·后端
摸鱼的老谭13 分钟前
Java学习之旅第二季-13:方法重写
java·学习·方法重写
云灬沙14 分钟前
IDEA2025无法更新使用Terminal控制台
java·intellij-idea·idea·intellij idea
Yield & Allure14 分钟前
IDEA在plugins里搜不到mybatisx插件的解决方法
java·ide·intellij-idea
yunmi_18 分钟前
安全框架 SpringSecurity 入门(超详细,IDEA2024)
java·spring boot·spring·junit·maven·mybatis·spring security
孤独斗士19 分钟前
解决Intellij IDEA控制台,logger.info(),system.out.println()等中文乱码问题
java·ide·intellij-idea
shepherd11123 分钟前
JDK 8钉子户进阶指南:十年坚守,终迎Java 21升级盛宴!
java·后端·面试
SimonKing44 分钟前
SpringBoot集成:5分钟实现HTML转PDF功能
java·后端·程序员