Java 8 java.time 在 Jackson JSON mapper 中序列化问题

在 Java 新的数据结构中可能会遇到下面的错误:

org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class java.time.LocalDateTime] from JSON String; no single-String constructor/factory method (through reference chain: MyDTO["field1"]->SubDTO["date"])

其实只需要添加 JSR-310 组件到项目中就可以了。

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.17.2</version>
        </dependency>

添加上面的依赖就可以了。