Reputation: 356
I am using jackson mapper in my application.
Below is the code snippet.
Code is also having null fields not being set in the pojo class.
Getting below error while writing as string in last line.
Getting issue while using jackson api.
dev.setActivationStatus("activationStatus");
dev.setAccountName("account");
dev.setServicePlan("service plan");
dev.setDeviceManufacturer("deviceManufacturer");
dev.setDeviceType("deviceType");
dev.setDeviceName("deviceName");
ObjectMapper obj =new ObjectMapper();
String devVal=obj.writeValueAsString(dev);```
java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonKey
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_231]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_231]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_231]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_231]
Any help will be useful
Upvotes: 1
Views: 2085
Reputation: 137
Here is what worked in my case.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.0-rc2</version>
</dependency>
<!-- Thanks for using https://jar-download.com -->
Upvotes: 0
Reputation: 18909
Make sure that you have the following dependency. Your error means it can not load the class com.fasterxml.jackson.annotation.JsonKey probably because it is not there. This class should be inside jackson-annotations project.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>{{choose a version here }}</version>
</dependency>
Upvotes: 1