I am attempting to deserialise a JSON object, which has Joda dateTime formats within it.
The deserialisation error is below:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
org.joda.time.DateTime
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('2019-08-02T17:33:24.000Z')at [Source: (StringReader); line: 1, column: 34] (through reference chain: Event$Builder["time"])
The object mapper I am using is:
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
public class Mapper {
private ObjectMapper objectMapper;
public Mapper() {
this.objectMapper = new ObjectMapper()
.registerModule(new GuavaModule())
.registerModule(new JodaModule())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public ObjectMapper getObjectMapper() {
return objectMapper;
}
}
With the dependencies of:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
And the method that tries to deserialise the JSON:
try {
Event = new Mapper()
.getObjectMapper()
.readValue(response, Event.class);
} catch (IOException e) {
fail(e);
}
How can I resolve this error please?
Many thanks in advance.