Java8 LocalDateTime to Joda LocalDateTime with jackson

Java8 LocalDateTime to Joda LocalDateTime with jackson

March 10, 2017
frontpage, Java
No Comment

Yesterday I fought a problem that didn’t seem to take as much time as it actually did, so I decided to write a few lines to share the learned lesson.

I had the following case: a spring boot rest service, that returns a JSON object, and a consumer that reads this object using RestTemplate. All was great but the fact that this object contains java.time.LocalDateTime in the service that had to be transformed to org.joda.time.LocalDateTime in the consumer. I decided not to implement custom deserializer and here is the other way I managed to make it work solving lots of org.springframework.http.converter.HttpMessageNotReadableException

The service

The problem in the service was that the date in the result looked like

After adding the following maven dependency

And updating to false the write-dates-as-timestamps property in application.yml

Got the nicer result

The client

In the client the following dependency had to be added

And then the RestTemplate had to “learn” about the JodaModule


Share on LinkedIn11Share on Facebook0Tweet about this on Twitter0Share on Google+2Share on Reddit0Email this to someoneDigg thisShare on StumbleUpon0