Spring Boot issues serializing java.time.LocalDateTime with Jackson to return ISO-8601 JSON timestamps?

后端 未结 3 1591
渐次进展
渐次进展 2021-02-13 02:48

I\'m working on converting some models in a spring-boot REST API app to use java 8\'s java.time.LocalDateTime instead of joda\'s DateTime. I want the t

3条回答
  •  忘掉有多难
    2021-02-13 03:37

    The NoSuchMethodError is because you are mixing versions of Jackson. Spring Boot 1.3.6 uses Jackson 2.6.7 and you are using 2.8.1 of jackson-datatype-jsr310.

    Spring Boot provides dependency management for Jackson, including jackson-datatype-jsr310, so you should remove the version from your pom. If you want to use a different version of Jackson, you should override the jackson.version property:

    
        2.8.1
    
    

    This will ensure that all your Jackson dependencies have the same version, thereby avoiding problems with mismatched versions.

    You can also, if you wish, remove your Java code that's configuring the ObjectMapper. The Java Time module will be automatically registered when it's in the classpath and writing dates as timestamps can be configured in application.properties:

    spring.jackson.serialization.write-dates-as-timestamps=false
    

提交回复
热议问题