gpt4 book ai didi

java - NoClassDefFound错误: org/codehaus/stax2/ri/Stax2WriterAdapter using jackson

转载 作者:行者123 更新时间:2023-11-29 04:20:50 26 4
gpt4 key购买 nike

我在使用 jackson 时遇到问题当我尝试转换json时至XML - 全documentation .

我的转换函数 -

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;
}

并收到此错误 - java.lang.NoClassDefFoundError: org/codehaus/stax2/ri/Stax2WriterAdapter ,我没有提及 Stax2WriterAdapter在我的类里面。

完整错误日志 -

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)

最佳答案

您引用的不是 Stax2WriterAdapter,而是 ToXmlGenerator是。您需要添加包含此类的 jar。根据maven central该 jar 的最后一个版本是:

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

顺便说一句,您引用的是相当旧的库和教程。我建议看一下more recent .

关于java - NoClassDefFound错误: org/codehaus/stax2/ri/Stax2WriterAdapter using jackson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49271724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com