6

Using this code :

import org.codehaus.jackson.map.ObjectMapper;
ObjectMapper objectMapper = new ObjectMapper();
String str = objectMapper.writeValueAsString(myObject);

I receive this Eclipse error:

The type org.codehaus.jackson.JsonGenerationException cannot be resolved. It is indirectly referenced from 
 required .class files

at line String str = objectMapper.writeValueAsString(myObject);

There are three 'JsonGenerationException' class types on my class path (you may have to save the image and open it separately to read the text in the image):

enter image description here

Is the reason I'm receiving this error message because JsonGenerationException is in two different jar files and Eclipse is unsure which on to use ? If so how can I fix it ?

I required this jar file : http://grepcode.com/snapshot/repo1.maven.org/maven2/org.codehaus.jackson/jackson-core-asl/1.9.4

blue-sky
  • 51,962
  • 152
  • 427
  • 752

2 Answers2

12

Make sure that the JAR containing org.codehaus.jackson.JsonGenerationException is on your classpath, e.g., by using jackson-core-asl POM.

reprogrammer
  • 14,298
  • 16
  • 57
  • 93
  • Hi, I am new to Java. Having the same problem. When I tried to import org.codehaus.jackson.map, it shows the error message "cannot be resolved". I read your reply but don't know how to use this xml file and where to put it. I assume it's under Configure build path, right? Could you please walk me through the process? Thanks. – Q-ximi Dec 05 '14 at 20:18
  • 1
    I downloaded GOOGLE-API-CLIENT, but there is no org.codehauls.jackson.JsonGenerationException folder. – Q-ximi Dec 05 '14 at 20:26
  • Worked for me, if anyone is wondering how to add jar to classpath check here https://stackoverflow.com/questions/3280353/how-to-import-a-jar-in-eclipse – jaafar Nasrallah May 26 '17 at 07:00
1
import org.codehaus.jackson.map.ObjectMapper;

and also,you have to add jackson-core-asl-XXX.jar to build path.

Marian Nasry
  • 821
  • 9
  • 22
hiallen
  • 29
  • 2