class com.alibaba.fastjson2.JSONObject cannot be cast to class com.ruoyi.sys
class com.alibaba.fastjson2.JSONObject cannot be cast to class com.ruoyi.sys
- ry-cloud
- 报错
- 原因
- 解决
ry-cloud
报错
系统监控→在线用户打开后报错
报错信息如下
class com.alibaba.fastjson2.JSONObject cannot be cast to class com.ruoyi.sys
原因
@type导致,无法转换为 LoginUser 对象
{"@type":"com.ruoyi.common.core.domain.model.LoginUser","browser":"Chrome 10","deptId":103,"expireTime":2302603674631,"ipaddr":"192.168.3.29","loginLocation":"内网IP","loginTime":1702603734631,"os":"Windows 10","permissions":["*:*:*"],"token":"e2b289ff-a2f6-4f64-971b-5ddb48984a09","user":{"admin":true,"avatar":"/profile/avatar/2023/12/14/blob_20231214164146A002.png","createBy":"admin","createTime":"2022-08-16 14:04:14","delFlag":"0","dept":{"ancestors":"0,100,101","children":[],"deptId":103,"deptName":"研发部门","leader":"赵","orderNum":1,"params":{"@type":"java.util.HashMap"},"parentId":101,"status":"0"},"deptId":103,"email":"op@163.com","loginDate":"2023-12-14 16:48:48.18","loginIp":"127.0.0.1","nickName":"管理员1","params":{"@type":"java.util.HashMap"},"password":"$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2","phonenumber":"15888888746","remark":"管理员","roles":[{"admin":true,"dataScope":"1","deptCheckStrictly":false,"flag":false,"menuCheckStrictly":false,"params":{"@type":"java.util.HashMap"},"roleId":1,"roleKey":"admin ","roleName":"超级管理员 ","roleSort":1,"status":"0"}],"sex":"1","status":"0","userId":1,"userName":"admin"},"userId":1,"username":"admin"}
解决
String redisServiceJson = JSONObject.toJSONString(redisService.getCacheObject(key));
LoginUser user = JSON.parseObject(redisServiceJson, LoginUser.class);