java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonInclude$Value

JavaJacksonWordpress Json-Api

Java Problem Overview


I am trying to convert my json string to java object and I am getting error

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonInclude$Value
	at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:45)
	at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:535)
	at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:452)
	at com.allianz.cmis.util.ApacheHttpClientGet.main(ApacheHttpClientGet.java:65)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonInclude$Value
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	... 4 more

Here is my json string and my code snippet

json string {'ctpnsw': [{'abc' , 'def' }]}

Model

    public class Fields {
    	
    	 private List<String> ctpnsw;
    
    	public List<String> getCtpnsw() {
    		return ctpnsw;
    	}
    
    	public void setCtpnsw(List<String> ctpnsw) {
    		this.ctpnsw = ctpnsw;
    	}
    	
    }

Java code

`ObjectMapper mapper = new ObjectMapper();
			    List<Fields> list = mapper.readValue(output, TypeFactory.defaultInstance().constructCollectionType(List.class,Fields.class));
			    System.out.println(list);`

Java Solutions


Solution 1 - Java

How about adding this to your pom.xml

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

Solution 2 - Java

Jackson marshalling/unmarshalling requires following jar files of same version.

  1. jackson-core

  2. jackson-databind

  3. jackson-annotations

Make sure that you have added all these with same version in your classpath. In your case jackson-annotations is missing in classpath.

Solution 3 - Java

I had the same error message. In my case, Jackson consisted of multiple JAR files. Sadly, they had different versions of jackson-core and jackson-annotations which resulted in the above exception.

Maybe you don't have the jackson-annotation JAR in your classpath, at least not in the correct version. You can analyze the used library versions with the command mvn dependency:tree.

Solution 4 - Java

I had different version of annotations jar. Changed all 3 jars to use SAME version of databind,annotations and core jackson jars

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

Solution 5 - Java

Even though this answer was too late, I'm adding it because I also went through a horrible time finding answer for the same matter. Only different was, I was struggling with AWS Comprehend Medical API.

At the moment I'm writing this answer, if anyone come across the same issue with any AWS SDKs please downgrade jackson-annotaions or any jackson dependencies to 2.8. versions.* The latest 2.9.* versions does not working properly with AWS SDK for some reason. Anyone have any idea about the reason behind that feel free to comment below.

Just in case if anyone is lazy to google maven repos, I have linked down necessary repos.Check them out!

Solution 6 - Java

Get all 3 jackson jars and add them to your build path:

https://mvnrepository.com/artifact/com.fasterxml.jackson.core

Solution 7 - Java

Use jackson-bom which will have all the three jackson versions.i.e.jackson-annotations, jackson-core and jackson-databind. This will resolve the dependencies related to those versions

Solution 8 - Java

I also faced the similar issues and by referring to the above solutions i was able to resolve the issue.

All the dependencies must have same version.

Following are the dependencies added in the pom.xml file

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


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


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

Solution 9 - Java

this is a version problem change version > 2.4 to 1.9 solve it

<dependency>  
<groupId>com.fasterxml.jackson.jaxrs</groupId>  
<artifactId>jackson-jaxrs-xml-provider</artifactId>  
<version>2.4.1</version>  

to

<dependency>  
<groupId>org.codehaus.jackson</groupId>  
<artifactId>jackson-mapper-asl</artifactId>  
<version>1.9.4</version>  

Solution 10 - Java

Use Jackson-annotations.jar will solve the problem, as it worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser327126View Question on Stackoverflow
Solution 1 - JavaMonoThreadedView Answer on Stackoverflow
Solution 2 - JavaVinoView Answer on Stackoverflow
Solution 3 - JavaMarcus K.View Answer on Stackoverflow
Solution 4 - JavaSaurabhView Answer on Stackoverflow
Solution 5 - JavaPiumal KulasekaraView Answer on Stackoverflow
Solution 6 - JavaBaked InhalfView Answer on Stackoverflow
Solution 7 - JavaPramod ItagiView Answer on Stackoverflow
Solution 8 - JavaJagratView Answer on Stackoverflow
Solution 9 - JavaJijun JiangView Answer on Stackoverflow
Solution 10 - JavaSatya PrakashView Answer on Stackoverflow