64

I need to convert json to pojo. I Decided to use jackson and have added jackson-core-2.2.0.jar, jackson-databind-2.4.4.jar and jackson-annotations-2.1.2.jar to my project's classpath

I created following Main class:

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;

public class Json {
private static String SRC= "";

  public static void main(String[] args) {

      AwardList awardList = null;
      ObjectMapper mapper = new ObjectMapper();

      try{
          awardList = (AwardList) mapper.readValue(new URL(SRC), AwardList.class);
      }catch (JsonGenerationException e){
          e.printStackTrace();
       } catch (JsonMappingException e){
          e.printStackTrace();
       } catch (IOException e){
          e.printStackTrace();
       }
       System.out.println(awardList);

  }
}

And following AwardList class:

public class AwardList {

    private Flights[] flights;
    private String[] connections;

    private SaverEconomy saverEconomy;
    private StandartEconomy standartEconomy;
    private SaverBusiness saverBusiness;
    private StandartFirst standartFirst;
    private SaverFirst saverFirst;


    public Flights[] getFlights() {
        return flights;
    }

    public void setFlights(Flights[] flights) {
        this.flights = flights;
    }

    public SaverEconomy getSaverEconomy() {
        return saverEconomy;
    }

    public void setSaverEconomy(SaverEconomy saverEconomy) {
        this.saverEconomy = saverEconomy;
    }

    public StandartEconomy getStandartEconomy() {
        return standartEconomy;
    }

    public void setStandartEconomy(StandartEconomy standartEconomy) {
        this.standartEconomy = standartEconomy;
    }

    public SaverBusiness getSaverBusiness() {
        return saverBusiness;
    }

    public void setSaverBusiness(SaverBusiness saverBusiness) {
        this.saverBusiness = saverBusiness;
    }

    public StandartFirst getStandartFirst() {
        return standartFirst;
    }

    public void setStandartFirst(StandartFirst standartFirst) {
        this.standartFirst = standartFirst;
    }

    public SaverFirst getSaverFirst() {
        return saverFirst;
    }

    public void setSaverFirst(SaverFirst saverFirst) {
        this.saverFirst = saverFirst;
    }

    public String[] getConnections() {
        return connections;
    }

    public void setConnections(String[] connections) {
        this.connections = connections;
    }
}

I want to convert json to pojo and save it in the database. I keep getting following error:

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
  at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:457)
  at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:379)
  at Json.main(Json.java:72)
Vogel612
  • 5,620
  • 5
  • 48
  • 73
jbakirov
  • 936
  • 2
  • 10
  • 15
  • 5
    Why you are using different versions of Jackson jars? You have jackson-core, jackson-databind, jackson-annotations but all of them has different versions? As a first step I would recommend to use the same release versions. Just for the info version 2.5 was released today. – Ilya Ovesnov Jan 02 '15 at 18:32
  • 2
    Your have another version of jackson jars which are loading before these jars. check the other version and remove those – NullPointerException Jan 02 '15 at 18:33
  • 1
    Worked for me too by using same versions : – Imeksbank Feb 09 '18 at 13:26

7 Answers7

112

I was getting the exactly same issue. I was using Maven for dependency management and had added dependency for jackson-databind module only like this

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

and then I resolved it by doing this.. I added its transitive dependencies explicitly with the same jackson.version mentioned for each of them in the pom.xml file, as guided here

<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>
Priya Aggarwal
  • 1,254
  • 1
  • 10
  • 5
  • This worked for me, but note this jar should then occur in the classpath before the jars with the earlier version of jackson. – shaneb Oct 19 '17 at 21:14
  • 1
    This worked for me..thanks.. i have added above both whith my jackson-databind dependancy – Nilesh Nov 16 '17 at 09:52
  • I am using 2.10 version for all three, I m getting this error. Which version would you suggest to resolve this issue . – Vijay Oct 18 '19 at 08:07
  • If anyone's getting this error after manually copying the three jackson-\*.jar-s under Tomcat's WEB-INF/lib, make sure you don't have older exploded jars under WEB-INF/classes/com/fasterxml/\*. – lainatnavi Oct 27 '20 at 15:51
  • This worked for me with version 'v2.14.2' for 'jackson-databind' and 'jackson-dataformat-yaml' and the two additional dependencies mentioned in the answer. – juanmi Mar 09 '23 at 15:17
24

I came here with a similar issue on Google App Engine. Here is how I fixed it.

First I ran:

mvn dependency:tree

To find who is using the older version. I then excluded that from the offending dependency like so:

<dependency>
    <groupId>com.google.appengine.tools</groupId>
    <artifactId>appengine-gcs-client</artifactId>
    <version>0.6</version>
    <exclusions>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Next I added the newer version of the dependency in my pom.xml:

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

Hope this help others who stumble here.

Jeffrey Hawkins
  • 269
  • 2
  • 2
  • 1
    If you're using gradle, it should something like this. implementation ("com.google.api-client:google-api-client:1.23.0") { exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core' } – aaronvargas Jul 18 '18 at 17:31
5

I had the same issue. There was some incompatibility between the jackson-version 2.6.3 and another dependency (graphaware-framework-embedded).

I could resolve the issue by simply removing the dependency on jackson in my own pom and just let the other dependency load whatever jackson-version it needed.

Tobias Gassmann
  • 11,399
  • 15
  • 58
  • 92
3

As of now latest redisson

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson</artifactId>
    <version>3.13.4</version>
</dependency>

Latest Jackson jackson.version property is 2.11.2 for me

    <!-- faster JSON -->
    <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>

Updating Eclipse references, without this runner configs were accessing earlier edition of jackson project.

eclipse:eclipse -U
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83
2

I faced the same issue just now while upgrading my project from spring 3 to 4.1.6.

A little background for reference, just in case if it helps anyone running into same issue===> First, it prompted me with error for mappingJacksonconverter vs mappingJackson2converter since the former doesn't exist anymore with spring 4. Once I changed those references in code, I ran into issue with my dispatcher servlet since it had xsd definitions from spring 3 support. Once that's corrected, my last step in journey was this error which you all faced as well.

My solution: I had older versions of following jars: jackson-annotations, jackson-core, jackson-databind, jackson-core-asl, jackson-mapper-asl

I upgraded first 3 jars to 2.10.0.pr1 release and last 2 to 1.9.13 release.

I also had one more older jar i.e.com.fasterxml.jackson.core.jar which I had to remove as well. Anyways, as error suggested this was the key reason for the mismatch (Like Tobias said in comment prior to mine)

I think only last paragraph is important from this particular question point of view, but I am hoping my narration of issues faced leading up to that may help someone saving 4-5 hrs :) Cheers, folks!

mrana
  • 161
  • 1
  • 7
1

For me, I updated the version to a recently released version i.e. 2.12.4 and it worked fine.

Note: I was using another project inside the build path of a larger project in eclipse. The jackson update was done inside the pom.xml file of the smaller project.

Onkar Singh
  • 109
  • 2
  • 10
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 11 '21 at 01:31
  • 1
    I upgraded from Jackson `2.11.4` to version `2.12.4`, the mapping error was fixed. – cstroe Dec 17 '21 at 03:41
0

I have updated jackson dependency version in my maven project from 2.7.4 to 2.15.0 due to vulnerabilities in older versions. After updating I am getting an exception NoClassDefFoundError. I tried to use jackson BOM 2.15.0 but still getting that exception. How to resolve this exception?

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.apache.felix.scr.impl.inject.ComponentConstructor.<init>(ComponentConstructor.java:95) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.inject.ComponentMethodsImpl.initComponentMethods(ComponentMethodsImpl.java:106) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.initDependencyManagers(AbstractComponentManager.java:1008) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.collectDependencies(AbstractComponentManager.java:1026) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:935) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:900) [org.apache.felix.scr:2.1.16]
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:348)
... 52 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException not found by com.dunkindonuts.aem.ddcom-ui-businesslogic [791]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
Pragya
  • 11
  • 2