Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialization of Java 8 ZonedDateTime with Jackson and JavaTimeModule

I'm trying to use Jackson to serialize and deserialize objects (marshall/unmarshall) from and to JSON. Some of these objects have Java 8 LocalDate and ZonedDateTime. I've read here that the best option is to use jackson-datatype-jsr310

serialize/deserialize java 8 java.time with Jackson JSON mapper

However, when I try to use this:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());

I get this error:

java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule

Any clue? I'm using Jackson 2.6.0, jackson-datatype-jsr310 2.6.0 and am deploying to Tomcat 8.

Thanks and best regards

like image 601
Faliorn Avatar asked Aug 08 '15 17:08

Faliorn


People also ask

Does Jackson use Java serialization?

This short tutorial shows how the Jackson library can be used to serialize Java object to XML and deserialize them back to objects.

Does Jackson serialize getters?

Jackson by default uses the getters for serializing and setters for deserializing.

Does Jackson need serializable?

Jackson actually doesn't need classes to implement Serializable but I'm going to add it anyway. Writing about a serialization framework and not implementing Serializable might seem strange.

How does Jackson serialize date?

It's important to note that Jackson will serialize the Date to a timestamp format by default (number of milliseconds since January 1st, 1970, UTC).


1 Answers

In the end, the problem was I had a different version of Jackson, due to a dependency with Jongo. jackson-datatype-jsr310 2.6.0 needs Jackson 2.6.0 and Jackson 2.4.1 was being deployed.

like image 106
Faliorn Avatar answered Sep 19 '22 22:09

Faliorn