Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be..
在对peopleJson反序列化时候报错:
Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be cast to com.exa.demo2.PO.PeopleInfoPO
问题是因为:在使用String peopleJson = JSON.toJSONString(peopleInfoPO)没有加入类型信息SerializerFeature.WriteClassName
如果
把String peopleJson = JSON.toJSONString(peopleInfoPO)
改为
String peopleJson =JSON.toJSONString(peopleInfoPO,SerializerFeature.WriteClassName)
问题就解决了!