2018-03-13 09:22:58,445 WARN [http-nio-9988-exec-3] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not construct instance of java.time.LocalDate: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.LocalDate: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@67064c65; line: 1, column: 63] (through reference chain: java.util.ArrayList[0]->com.didispace.UserDto["birthday"])
分析解决
对于上面的错误信息 JSON parse error: Can not construct instance of java.time.LocalDate: no suitable constructor found, can not deserialize from Object value ,熟悉Spring MVC的童鞋应该马上就能定位错误与 LocalDate 的反序列化有关。但是,依然会有很多读者会被这段错误信息 java.util.ArrayList[0]->com.didispace.UserDto["birthday"] 所困惑。我们命名提交的 UserDto["birthday"] 是个 LocalDate 对象嘛,跟 ArrayList 列表对象有啥关系呢?