Serialization of Java 8 ZonedDateTime with Jackson and JavaTimeModule

10,035

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.

Share:
10,035

Related videos on Youtube

Faliorn
Author by

Faliorn

Videogames, sushi and rock and roll!

Updated on June 04, 2022

Comments

  • Faliorn
    Faliorn almost 2 years

    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

  • Iwo Kucharski
    Iwo Kucharski almost 8 years
    I had the same problem with java.time.LocalDate and resolved it using the same version of jackson-core and jackson-databind. In my case it was version 2.7.4 for both dependencies.