com.google.gson.internal.LinkedTreeMap cannot be cast to entity

来源:互联网 发布:中传在线 网络教育 编辑:程序博客网 时间:2024/05/22 15:54

问题:
后台报错: com.google.gson.internal.LinkedTreeMap cannot be cast to com.xie.Teacher
原因json转list的时候类型没写正确
解决办法:

import com.google.gson.reflect.TypeToken;import java.lang.reflect.Type;Type listType = new TypeToken<List<Teacher>>() {}.getType();        List<Teacher> list=JsonUtil.fromJson(jsonStr, listType);        for(int i=0;i<list.size();i++){            System.out.println(list.get(i).getName());        }        String jsonResult=JsonUtil.toJson("");        return jsonResult;
阅读全文
0 0
原创粉丝点击