简体   繁体   中英

NoClassDefFoundError: org/codehaus/stax2/ri/Stax2WriterAdapter using jackson

I have a problem using jackson when I try to convert json to XML - full documentation .

My converting function -

public org.w3c.dom.Element jsonToXml(JsonNode json) throws JsonProcessingException, ParserConfigurationException{
        org.w3c.dom.Element toReturn = null;
        XmlMapper xmlMapper = new XmlMapper();
        String jsonString = xmlMapper.writeValueAsString(json.toString());
        javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        DocumentBuilder db = b.newDocumentBuilder();
        Document doc = db.newDocument(); 
        toReturn = doc.createElement(jsonString); 
        //return Element
        return toReturn;
    }

And getting this error - java.lang.NoClassDefFoundError: org/codehaus/stax2/ri/Stax2WriterAdapter , I do not any reference to Stax2WriterAdapter in my class.

Full error log -

com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet GtoQuotesServlets in application MatafServiceServletsEAR. Exception created : java.lang.NoClassDefFoundError: org/codehaus/stax2/ri/Stax2WriterAdapter at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.<init>(ToXmlGenerator.java:156) at com.fasterxml.jackson.dataformat.xml.XmlFactory.createGenerator(XmlFactory.java:366) at com.fasterxml.jackson.dataformat.xml.XmlFactory.createGenerator(XmlFactory.java:27) at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2927) at mataf.service.servlets.GtoQuotesServlets.jsonToXml(GtoQuotesServlets.java:333) at mataf.service.servlets.GtoQuotesServlets.writeTumlugimToLog(GtoQuotesServlets.java:177) at mataf.service.servlets.GtoQuotesServlets.doPost(GtoQuotesServlets.java:143) at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:944) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306) at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84) at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1819) at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175) at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1660)

You are not referencing Stax2WriterAdapter but ToXmlGenerator is. You need to add the jar that contains this class. According to maven central last version of that jar would be:

<dependency>
    <groupId>org.codehaus.woodstox</groupId>
    <artifactId>stax2-api</artifactId>
    <version>4.0.0</version>
</dependency>

BTW you're referencing pretty old library and tutorial. I suggest looking at something more recent .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM