原报错代码写法:
//获取table,强转成list集合
List<OrderMatchingProcess> listNew = (List<OrderMatchingProcess>) message.getFormData().get("table");
报错如下:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.*.
通过调试,发现是LinkedHashMap类型,而不是实体类
解决方法如下:
//获取table,转成list集合
ObjectMapper mapper = new ObjectMapper();
List<OrderMatchingProcess> list = (List<OrderMatchingProcess>) message.getFormData().get("table");
List<OrderMatchingProcess> listNew= mapper.convertValue(list, new TypeReference<List<OrderMatchingProcess>>() { });
引入:
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;文章来源:https://www.toymoban.com/news/detail-767747.html
调试:
问题解决。文章来源地址https://www.toymoban.com/news/detail-767747.html
到了这里,关于java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to*****的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!