4

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]
asked Mar 3, 2021 at 9:47
3
  • 2
    It looks like an incompatibility between different com.fasterxml artifact versions. Try using the latest version (I think it's 2.12.1) 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. Commented Mar 3, 2021 at 10:11
  • 2
    Yes, this is the solution! Commented Mar 3, 2021 at 11:03
  • @k314159 You should make your comment an answer since it is the correct answer (2.12.1 contains that method). Commented May 1, 2021 at 13:26

1 Answer 1

5

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.

answered May 3, 2021 at 14:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.