java.util.LinkedHashMap Cannot Be Cast To

摘要: Jackson转换泛型List出现错误java.util.LinkedHashMap cannot be cast to com.xxx ObjectMapper mapper = new ObjectMapper(); mapper.readValue(new File(fileAPI.getRo阅读全文

Jackson转换泛型List出现错误java.util.LinkedHashMap cannot be cast to com.xxx

ObjectMapper mapper = new ObjectMapper();

mapper.readValue(new File(fileAPI.getRoot(), jsonFileName), Map.class);

当使用Jackson解析具体的bean时,应该使用尽量详尽的本来解析,而使用Map.class、List.class解析时,会对具体的bean解析不出

使用new TypeReference<List>(){},或者具体的Object.class,

注:Object为具体的解析类