赞
踩
问题具体描述:接口获取的数据,封装在CXFResponseVo,从该类获取list,遍历list时,需要获取list中的对象,报错
原因:list存储的并不是正常的java实体类,需要将list转成json字符串,再转回list,并且在转回的时候设置格式
- String outsourceOrderReport = outsourceTaskInter.getOutsourceOrderReport(jsonmap);
- CXFResponseVo cxfResponseVo = null;
- if (outsourceOrderReport != null) {
- cxfResponseVo = MyJsonUtil.str2obj(outsourceOrderReport, CXFResponseVo.class);
- }
- List<OutsourcingOrderDetails> resultList= (List<OutsourcingOrderDetails>) cxfResponseVo.getData();
使用jackjson框架
- //再次转换list
- ObjectMapper objectMapper=new ObjectMapper();
- String tranStr = null;
- List<OutsourcingOrderDetails> tranList=null;
- try {
- tranStr = objectMapper.writeValueAsString(resultList);
- JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, OutsourcingOrderDetails.class);
- tranList= objectMapper.readValue(tranStr, javaType);
- } catch (IOException e) {
- e.printStackTrace();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。