Skip to content
Advertisement

how to resolve Joda date/time type `org.joda.time.DateTime` not supported by default

I have an existing web-app and unfortunately the ‘time’ fields in the DB are not converted to zulu time. Instead we are using org.joda.time.DateTime as our datetime and timezone encapsulator.

I am in the process of updating from hibernate 4.3.7.Final to 5.3.20.Final
Also, we are letting hibernate manage the translation of these DateTime objects to/from the db using

JavaScript

Running this on hibernate 5 gives this error:

JavaScript

wondering why this would work in hibernate 4 before the update to 5? I am using joda-time version 2.1 but have been able to reproduce the issue in 2.9.7

I have also looked and found this thread Persist Joda-time’s DateTime via Hibernate but, their solution was to convert to Joda’s LocalDateTime which unless I am mistaken does not support time zones which are needed for my use case.

Edit: I have added the requested module, and I still get the same error. I have tested this with Joda versions: 2.10.10, 2.9.7, and 2.1

JavaScript

Advertisement

Answer

You have to register the JodaModule on your ObjectMapper, like this:

JavaScript

Prior to Jackson 2.12, you wouldn’t get the error you’re seeing because Jackson would default to using the BeanSerializer if it encountered a Joda object. Here’s the code added in 2.12 that now raises an error instead:

https://github.com/FasterXML/jackson-databind/blob/2.13/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java#L288

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement