Jackson: SerializationConfig.hasExplicitTimeZone()

Viewed 2453

I,m trying to deserialize json to object, which contains fields with OffsetDateTime-type:

public class Appeal   {

  @JsonProperty("createTime")
  private OffsetDateTime createTime;

For this purpuse I configure my ObjectMapper with JavaTimeModule-support:

public class JsonObjectMapper extends ObjectMapper {

   private static ObjectMapper objectMapper = new JsonObjectMapper();

   private JsonObjectMapper() {
       objectMapper = createObjectMapper();
   }

   private ObjectMapper createObjectMapper() {
       ObjectMapper objectMapper = new ObjectMapper();
       objectMapper.registerModule(new JavaTimeModule());
       return objectMapper;
   }

   public static ObjectMapper getMapper() {
       return objectMapper;
    }
}

But I receive the following Exception:

java.lang.NoSuchMethodError: 'boolean com.fasterxml.jackson.databind.SerializationConfig.hasExplicitTimeZone()'
at com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializerBase.formatValue(InstantSerializerBase.java:144) ~[jackson-datatype-jsr310-2.12.1.jar!/:2.12.1]
1 Answers

It looks like an incompatibility between different com.fasterxml artifact versions. Try using the latest version (I think it's 2.12.3) for everything.

Btw the way you're using this class as a singleton seems a bit convoluted. You could simply initialise the static objectMapper to createObjectMapper() and have an empty constructor, and the class then doesn't need to extend ObjectMapper.

Related