NoClassDefFoundError JsonAutoDetect while parsing JSON object

北慕城南 提交于 2019-11-26 22:57:26
i_am_jorf

For those who come here in the future, the answer is:

If you've only copied jackson core and jackson databind, you need jackson annotations to use the ObjectMapper.

For example, make sure you have something like this:

[16:32:01]:/android-project/libs     master]$ ls -lAF
total 2112
-rw-r--r--@ 1 jeffamaphone  staff   33525 Jun 18 16:06 jackson-annotations-2.0.2.jar
-rw-r--r--@ 1 jeffamaphone  staff  193693 Jun  7 16:42 jackson-core-2.0.2.jar
-rw-r--r--@ 1 jeffamaphone  staff  847121 Jun 18 15:22 jackson-databind-2.0.2.jar

To expand on @jeffamaphone's excellent answer, for maven users

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

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

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

Or the following gradle configuration:

compile 'com.fasterxml.jackson.core:jackson-core:2.2.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.2'

If you use maven and have all libraries in place as in my case a simple mvn clean and mvn install fixed problem.

If you are/were using tomcat while developing in eclipse and got this error(maybe because you pressed republish/clean),

a right click on the project->Maven->Update Project...

solved this issue for me.

In addition, i did include also the dependencies from Johan Sjöberg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!