异常信息:(很很明显是反序列化错误)
Cannot construct instance of `java.time.LocalDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-10-21 13:57:38')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->com.construn.vehicle.tmrp.entity.IncomeSummaryRepInfo["createTime"])
java.lang.IllegalArgumentException: Cannot construct instance of `java.time.LocalDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-10-21 13:57:38')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->com.construn.vehicle.tmrp.entity.IncomeSummaryRepInfo["createTime"])
错误场景:数据库createTime字段为datetime类型;实体类中为LocalDateTime类型;返回给前端,修改的时候,前端再返回来,就报了这个错误。(说明:我这里,前端穿的是一个实体类list;在controller中用map接收的)
解决:我用的 ObjectMapper转的list
List<xxxx> list1 = (List<xxxx>) map.get("list");
ObjectMapper mapper = new ObjectMapper();
//序列化的时候序列对象的所有属性
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
List<xxxx> list = mapper.convertValue(list1, new TypeReference<List<xxxx>>() { });
主要是红色两行,其它的都是把前端传的值转换成list
说明:该场景只是本人遇到的,在对应的方法类转换,这有可能不适用您,我是偷懒,直接在方法中写,如果不实用,我想您可能要写一个配置文件类了;