原报错代码写法:
//获取table,强转成list集合List listNew = (List) message.getFormData().get("table");
报错如下:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.*.
通过调试,发现是LinkedHashMap类型,而不是实体类
解决方法如下:
//获取table,转成list集合 ObjectMapper mapper = new ObjectMapper(); List list = (List) message.getFormData().get("table"); List listNew= mapper.convertValue(list, new TypeReference<List>() { });
引入:
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
调试:
问题解决。