3

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!

Marc B
  • 356,200
  • 43
  • 426
  • 500
craigtb
  • 647
  • 5
  • 12
  • 30
  • is org.codehaus.jettison jar in your class path? – Jayaram Jun 23 '14 at 15:59
  • To understand what you have written, does your function parse any request into InputDTO? My question is, what if the data for InputDTO changes from request to request, would it be better to return a generic Class> – portfoliobuilder May 26 '16 at 19:04

2 Answers2

3

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>
Community
  • 1
  • 1
Jayaram
  • 1,715
  • 18
  • 30
  • i am using eclipse and when i go to the java build path the jettison-1.3.3.jar is under the Web App Libraries. Its in the WEB-INF/lib folder. does this not do that? – craigtb Jun 23 '14 at 17:06
  • @craigtb: Ok it should...Please have a look http://stackoverflow.com/questions/16364820/dynamic-web-project-java-lang-classnotfoundexception-despite-jar-file-in-the and http://stackoverflow.com/questions/8582199/tomcat-6-not-loading-jars-from-web-inf-lib – Jayaram Jun 23 '14 at 17:21
0

Use this for Android

implementation ('com.thoughtworks.xstream:xstream:1.4.9') {
    exclude group: 'xmlpull', module: 'xmlpull'
}

implementation 'com.github.codehaus:jettison:jettison-1.3.7'
Hamza Khan
  • 1,433
  • 13
  • 19