NoClassDefFoundError JsonAutoDetect when parsing a JSON object

I am developing a webapp using Amazon cloud services and I need to use JSON objects. As my project is set up, I have an HTML form in which the user will fill in their information and submit. After sending, the data will be placed in the online database, and an confirmation email will be sent to them. Before I can send data to the database, I need to put all this in a JSON object. My servlet made in Java looks like this:

public class FormHandling extends HttpServlet { //doGet function public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // In this part of the code I take in the user data and build an HTML // page and return it to the user // Create String Mapping for User Data object Map<String,Object> userData = new HashMap<String,Object>(); // Map the names into one struct. In the code below we are creating // values for the nameStruct from the information the user has // submitted on the form. Map<String,String> nameStruct = new HashMap<String,String>(); nameStruct.put("fName", request.getParameter("fname")); nameStruct.put("lName", request.getParameter("lname")); nameStruct.put("mInit", request.getParameter("minit")); // Map the three email together (providing there are 3). // This is the same logic as the names. Map<String,String> emailStruct = new HashMap<String,String>(); emailStruct.put("email", request.getParameter("email1")); emailStruct.put("email", request.getParameter("email2")); emailStruct.put("email", request.getParameter("email3")); // Put Name Hash Value Pair inside User Data Object userData.put("name", nameStruct); userData.put("emails", emailStruct); userData.put("age", 22); // Create the Json data from the userData createJson(userData); // Close writer out.close(); } public File createJson(Map<String,Object> userData) throws JsonGenerationException, JsonMappingException, IOException { File user = new File("user.json"); // Create mapper object ObjectMapper mapper = new ObjectMapper(); // Add the userData information to the json file mapper.writeValue(user, userData); return user; } } 

When I submit the form using this code, I get the following error message:

java.lang.NoClassDefFoundError: com / quickxml / jackson / annotation / JsonAutoDetect com.fasterxml.jackson.databind.introspect.VisibilityChecker $ Std. (VisibilityChecker.java:169) com.fasterxml.jackson.databind.ObjectMapper. (ObjectMapper.java:197) edu.tcnj.FormHandling.createJson (FormHandling.java:115) edu.tcnj.FormHandling.doGet (FormHandling.java:104) edu.tcnj.FormHandling.doPost (FormHandling.java .servlet.http.HttpServlet.service (HttpServlet.java:641) javax.servlet.http.HttpServlet.service (HttpServlet.java:722)

Now I know that the error means that it does not find the Jackson databind data library. I am developing in Eclipse and from time to time I know that the build path gets confused, so I also put the libraries in the WebContent \ WEB-INF \ lib folder. This solved the problems that I had before. However, this time this does not seem to solve my problem. I even opened jar files to physically verify that the library and class are needed, and they are. I tried looking everything differently and studied different ways to enable the library, but nothing works.

+45
java json noclassdeffounderror eclipse web-applications
Apr 10 '12 at 18:24
source share
5 answers

For those coming here in the future, the answer is:

If you just copied jackson core and jackson databind , you need jackson annotations use 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 
+124
Jun 18 '12 at 23:33
source share

To extend on @jeffamaphone a great 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> 
+63
Oct 13
source share

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' 
+6
Jun 29 '14 at 10:32
source share

If you use maven and have all the libraries, as in my case, this is a simple problem with mvn clean and mvn install .

+1
Feb 19 '16 at 11:59
source share

If you / used tomcat during development in eclipse and received this error (possibly because you clicked republish / clean),

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

solved this problem for me.

In addition, I also included dependencies on Johan Sjöberg

0
Apr 7 '16 at 7:38
source share



All Articles