23

I'm using Jackson sample code to deserialize a POJO:

ObjectMapper m = new ObjectMapper();

This line throws a NoSuchMethodError:

Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class;)V
    at org.codehaus.jackson.map.type.TypeBase.<init>(TypeBase.java:15)
    at org.codehaus.jackson.map.type.SimpleType.<init>(SimpleType.java:45)
    at org.codehaus.jackson.map.type.SimpleType.<init>(SimpleType.java:40)
    at org.codehaus.jackson.map.type.TypeBindings.<clinit>(TypeBindings.java:18)
    at org.codehaus.jackson.map.type.TypeFactory._fromType(TypeFactory.java:525)
    at org.codehaus.jackson.map.type.TypeFactory.type(TypeFactory.java:61)
    at org.codehaus.jackson.map.ObjectMapper.<clinit>(ObjectMapper.java:179)
    at com.me.util.ctrl.BillingJobStatus.fromJson(BillingJobStatus.java:37)

I don't get it

linuxbuild
  • 15,843
  • 6
  • 60
  • 87
Mojo
  • 2,687
  • 5
  • 30
  • 42
  • The exclusion mechanism worked when facing this error with hadoop. I also had to exclude jackson-core-asl from the hadoop core dependency. – Chitra Oct 31 '12 at 18:11

9 Answers9

28

I'm guessing your Jackson JARs are out of sync. The JavaType class is in the jackson-core JAR, and the ObjectMapper class is in jackson-mapper.

Make sure these are both of the same version.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 6
    Yes, this is an unfortunate but common pitfall, which can easily occur, especially when using Maven. – StaxMan Feb 25 '11 at 03:32
  • @StaxMan agreed, it's a common pitfall but, without a doubt, Maven helps by explicitly declaring dependency versions. – Sean Connolly Apr 06 '14 at 22:41
  • 1
    @SeanConnolly true, I should probably have clarified; it's rather a generic issue with transitive dependencies, not really with Maven but modelling. – StaxMan Apr 07 '14 at 01:47
  • It doesn't seem to be as easy as this. There is only one version of jackson-mapper in maven. – markthegrea Feb 14 '20 at 18:42
5

The trick here is to exclude jackson from the dependencies that use it.

To check which dependencies import it, you can use the following maven command:

mvn dependency:tree -Dincludes=org.codehaus.jackson

wild_nothing
  • 2,845
  • 1
  • 35
  • 47
5

I had this same problem. The core jar was 1.7.1 while the mapper was 1.8.1. Note: To fix this for maven I added an exclusion and pulled down the proper version.

        <exclusions>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
            </exclusion>
        </exclusions>
Jeff
  • 51
  • 1
  • 1
3

In my case it was due to yammer-metrics library including an older version of jackson.

<dependency>
  <groupId>com.yammer.metrics</groupId>
  <artifactId>metrics-servlet</artifactId>
  <version>2.1.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Pratik Khadloya
  • 12,509
  • 11
  • 81
  • 106
3

In my case it was the amazonaws sdk that caused this. Using just the exclusion for jackson-mapper-asl didn't work but using an exclusion for core and mapper did:

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.3.13</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-asl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
user1084563
  • 2,149
  • 17
  • 28
2

While working on Hadoop, I eliminated this error by setting the following exclusions

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>1.0.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
        </exclusion>
    </exclusions>   
</dependency>
Marko
  • 20,385
  • 13
  • 48
  • 64
1

it is beacuse of @RequestBody use different jars for different spring versions : if using spring 4 than have to add different jars :

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

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

if using spring 3 have to use this jar :

 <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.5.0</version>
</dependency>
abhishek ringsia
  • 1,970
  • 2
  • 20
  • 28
  • Until I started using annotation @RequestBody (Spring v4.0.6) everything worked fine with jackson-all-1.9.6.jar. Using jackson-all-1.9.6.jar and Spring v3.x works fine. – grajsek Nov 16 '16 at 21:18
0

Yes, anyone who is facing this issue, he should definetely investigate the dependencies with

mvn dependency:tree -Dincludes=org.codehaus.jackson

In my case, I had a jackson dependency on Atmosphere-Socket-io :

<dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-socketio</artifactId>
        <version>2.2.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-lgpl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-lgpl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

It took me several hours to track that down, thank you all guys for the above solutions which inspired me! Keep up the good work!

qgicup
  • 2,189
  • 1
  • 16
  • 13
0

I have faced this problem when migrating my WebApp from Tomcat 6 to Tomcat 8. On Tomcat6 and Tomcat7 my WebApp would start just fine, but on Tomcat8 I would get this exception(seems that T6 and T7 loads classes alphabeticaly but T8 doesn't - https://stackoverflow.com/a/26642798/1864614).

The problem was that I was having 2 versions of the class

org.codehaus.jackson.map.ObjectMapper
As answered by @wild_nothing I have checked dependency the tree to list all dependencies on org.codehaus.jackson

In my case the problem was that I had several versions of libraries that provided this class:
  • org.codehaus.jackson:jackson-mapper-lgpl:jar:1.5.0
  • org.codehaus.jackson:jackson-core-lgpl:jar:1.5.0
  • org.codehaus.jackson:jackson-mapper-asl:jar:1.8.2
  • org.codehaus.jackson:jackson-core-asl:jar:1.8.2

My solution was to exclude the older versions(1.5.0) and only leave the 1.8.2 version

<dependency>
        <groupId>cfm.foo</groupId>
        <artifactId>jive</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-lgpl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-lgpl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  • in this case jive was depending on older 1.5.0 version
Community
  • 1
  • 1
razvang
  • 1,055
  • 11
  • 15