java.lang.ClassCastException: cn.hutool.json.JSONObject cannot be cast toXXXX

问题复现:

 List<Test>  result =  (List)response.getData();
 Test  test = result.get(0);
 

然后就报错 :

java.lang.ClassCastException: cn.hutool.json.JSONObject cannot be cast to XXXX…

问题解决:

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;


 List<JSONObject>  result =  (List)response.getData();
 Test  test = JSONUtil.toBean(result.get(0),Test.class);

你可能感兴趣的:(后端报错,java)