0

I have string field in a json object that represents a date in the following format: 2019-04-09T16:29:25Z wrapped in double quotes, of course.

pratica.put("dataCreazionePratica", OffsetDateTime.parse("2019-04-09T16:29:25Z"));

I then use Jackson ObjectMapper to map my JSON to an object, that for said date is an OffsetDateTime object. I get the following error:

Cannot construct instance of `java.time.OffsetDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-04-09T16:29:25Z')

I do not undertand why in the error message I got the single quotes. I tried to change my json object like this:

pratica.put("dataCreazionePratica", OffsetDateTime.parse("2019-04-09T16:29:25Z"));

but then I got the following error:

Cannot construct instance of `java.time.OffsetDateTime` (no Creators, like default construct, exist): no int/Int-argument constructor/factory method to deserialize from Number value (2019)

It's like it's trying to read it as an integer... Is there any other way to parse a string date and obtain an OffsetDateTime?

esseara
  • 834
  • 5
  • 27
  • 47
  • 1
    Try to register `JavaTimeModule` module. See: [Problem with deserialization of LocalDateTime in Junit test](https://stackoverflow.com/questions/55107588/problem-with-deserialization-of-localdatetime-in-junit-test), [Feign jackson dateTime JsonMappingException](https://stackoverflow.com/questions/55028766/feign-jackson-datetime-jsonmappingexception), [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format) – Michał Ziober Apr 16 '19 at 13:14
  • 1
    First link didi the trick, thanks! – esseara Apr 16 '19 at 13:32

0 Answers0