Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson fails on deserializing String to Joda-Time

I'm using Spring Boot 1.5.6 with Jackson 2.8.8. When deserializing the answer of a REST call, Jackson fails with the following exception:

JSON parse error: Can not construct instance of org.joda.time.DateTime: no String-argument constructor/factory method to deserialize from String value ('2018-03-19T12:05:21.885+01:00')

It's true there is no String constructor, only an Object constructor in the DateTime object.

I included the jackson-datatype-joda dependency in my build.gradle file. These are the respective lines from the build.gradle:

compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: jacksonVersion
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: jacksonVersion
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5', version: jacksonVersion
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-joda', version: jacksonVersion

Is there any additional configuration I need to do?

PS: If I put the date String into a new DateTime("2018-03-19T12:05:21.885+01:00") it works fine.

Any ideas? Cheers!

like image 470
Tom Avatar asked Mar 19 '18 10:03

Tom


1 Answers

Did you register the JodaModule module in your ObjectMapper?

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
like image 73
Karol Dowbecki Avatar answered Sep 22 '22 06:09

Karol Dowbecki