1. Introduction
In this short article, we will present a solution for the Java 8 date/time type java.time.LocalDateTime
not supported by default exception. This kind of exception is thrown when we tried to convert an Object with LocalDateTime
from Java 8 using ObjectMapper
.
2. The java.lang.IllegalArgumentException
: Java 8 date/time type java.time.LocalDateTime not supported by default
When you face that kind of a warning your console log will probably have the following stack trace.
3. Solution for Java 8 date/time type java.time.LocalDateTime not supported by default
Actually, the exception gives us information about how to fix that problem. We need to Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
Java 8 date/time types.
First add
Jackson-Datatype-JSR310
dependency in yourpom.xml
(you can find the current version in Maven Repository):Next, we need to register the
JavaTimeModule
module:Using
registerModule
method onObjectMapper
:Using
findAndRegisterModules
method:Using
builder()
- this is possible since version 2.10:
4. Conclusion
In this article we presented how to fix java.lang.IllegalArgumentException: Java 8 date/time type java.time.LocalDateTime
not supported by default.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}