1
votes

I am getting this error when I run this toy example from:

http://howtodoinjava.com/2014/06/16/jackson-examples-convert-java-object-to-from-json/

My gradle file has:

dependencies {
    classpath('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
}

Error:

java -jar build/libs/pojo-test-0.1.0.jar

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonGenerationException

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
        at java.lang.Class.getMethod0(Class.java:2856)
        at java.lang.Class.getMethod(Class.java:1668)


Changing my gradle as per suggestion to include core-asl still gives the same errors (see changes):

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
        classpath('org.codehaus.jackson:jackson-core-asl:1.9.13')
    }
}
apply plugin: 'java'

jar {
    manifest {
        attributes 'Main-Class': 'JavaToJSONExample'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
    compile('org.codehaus.jackson:jackson-core-asl:1.9.13')
}
2
This may not be the direct issue, but you're using an obsolete (version 1) version of Jackson; the latest is 2.6.1 - chrylis -cautiouslyoptimistic-

2 Answers

1
votes

If you want to go with the old Jackson implementation, you need to also import jackson-core-asl:

  dependencies {
        classpath('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
        classpath('org.codehaus.jackson:jackson-core-asl:1.9.13')
    }
0
votes

Use this dependency in graddle

'com.fasterxml.jackson.core:jackson-core:2.6.1'

along with the mapper dependency. Also, kindly upgrade the mapper version with

'com.fasterxml.jackson.core:jackson-databind:2.6.1'