I have looked around on the web but can seem to get this working. I have a web service where i am trying to read JSON but i keep getting an error when i create the XStream object. here is the code i have and the error
public static InputDTO inputFromJson(HttpServletRequest request) throws IOException {
logger.debug("in inputfromjson");
XStream xstreamJson = new XStream(new JettisonMappedXmlDriver()); //this is where the code starts failing
logger.debug("after xstreamjson create");
xstreamJson.alias("tz", String.class);
InputDTO inputDTO = null;
try (InputStream is = request.getInputStream())
{
Object dto = xstreamJson.fromXML(is);
if (dto instanceof InputDTO) {
inputDTO = (InputDTO)dto;
}
}
logger.debug(inputDTO);
return inputDTO;
}
The error i am getting is
java.lang.ClassNotFoundException: org.codehaus.jettison.mapped.Configuration
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:48)
at com.homedepot.week3.XMLReader.inputFromJson(XMLReader.java:81)
I have read that i need to import the org.codehaus.jettison.json.*; but that doesn't seem to fix anything. Could someone please help with this? I'm sure its something simple.
Thanks!
ClassNotFoundException: The class its looking for is not available in your classPath
How To resolve Class Not Found Exception
for your stack trace it says org.codehaus.jettison.mapped.Configuration no found.
you are missing lib jettison, If you are using maven you can add
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.5</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With