List中不能直接转换成List,要先转换成List后Object再一个个转换成T
JsonResult jsonResult = new JsonResult();
List<Object> jsonList = null;
try {
jsonList = JSON.parseObject(json, List.class);
} catch (Exception e) {
log.error("错误提示:"+e.getMessage());
throw new ApiException(JsonResultEnum.BASICSDATA_ONLEONE);
}
List<BomDto> bomErrorDtos = new LinkedList<>();
for (Object o : jsonList) {
BomDto bomDto = JSONObject.toJavaObject((JSON) o, BomDto.class);
bomErrorDtos.add(bomDto);
}
可以避免一个个转换而出现无法是被的情况:
List<BomDto> studentList1 = JSON.parseArray(JSON.parseObject(json), BomDto.class);
之前一个个转出现无法识别Date类型:
Caused by: com.alibaba.fastjson.JSONException: can not cast to Date, value : 2019-12-02T03:58:39.000+0000