10

I am trying to map a Json string to a Java Object using ObjectMapper

ObjectMapper mapper = new ObjectMapper();
CustomerData customerData = mapper.readValue(customerDataString, customerData.class);

But when I do, I get this error

java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:530)

I looked online and checked for the incompatible dependencies in the pom.xml, and it appears to be the right version. So what am I missing?

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.0</version>
    </dependency>
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
William Roberts
  • 319
  • 2
  • 5
  • 21
  • 1
    I guess you have conflicting jackson-versions. You could check mvn dependency:tree and see if there are other conflicting jackson libs. – Hendrik Jander Jan 29 '16 at 22:14
  • 1
    Possible duplicate of [Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z](http://stackoverflow.com/questions/27746750/exception-in-thread-main-java-lang-nosuchmethoderror-com-fasterxml-jackson-co) – walen Nov 12 '16 at 08:24

2 Answers2

20

Following dependencies must be tally with each other. (Same Version)

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.version}</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>${jackson.version}</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>${jackson.version}</version>
</dependency>
Chinthaka Dinadasa
  • 3,332
  • 2
  • 28
  • 33
5

Make sure that you do not have an older version of artifactId "jackson-core" (< 2.3.0) as a dependency. You can try to add

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.6.0</version> 
</dependency>

as first dependency in your pom.

Rainer Montag
  • 493
  • 1
  • 6
  • 13