gpt4 book ai didi

java - 在 Websphere 上使用 jackson-dataformat-xml

转载 作者:行者123 更新时间:2023-12-02 09:13:29 27 4
gpt4 key购买 nike

我正在尝试使用 jackson-dataformat-xml 从 String 读取 XML:

String data = "<?xml version='1.0' encoding='UTF-8'?>"+
"<aa>"+
"<bb>bb</bb>"+
"</aa>";

XmlMapper xmlMapper = new XmlMapper();
JsonNode jsonNode = xmlMapper.readTree(data.getBytes());

每次我使用此代码调用 jsp 页面时,我都会在 WebSphere 上收到以下错误

[err] java.lang.UnsupportedOperationException: XMLInputFactory ne prend pas en charge cette m□thode : "createXMLStreamReader(Source)".
[err] at com.ibm.xml.xlxp2.api.stax.msg.StAXMessageProvider.throwUnsupportedOperationException(StAXMessageProvider.java:53)
[err] at [internal classes]
[err] at com.fasterxml.jackson.dataformat.xml.XmlFactory._createParser(XmlFactory.java:590)
[err] at com.fasterxml.jackson.dataformat.xml.XmlFactory._createParser(XmlFactory.java:29)
[err] at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:857)
[err] at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2572)
[err] at com.ibm._jsp._test_2D_jack._jspService(_test_2D_jack.java:121)
[err] at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:101)
[err] at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
[err] at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
[err] at [internal classes]

有什么想法吗?

我在我的项目中使用以下依赖项:

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.9</version>
</dependency>

最佳答案

使用 Woodstox 解析器

如果您使用独立客户端,则必须在 java 命令行上为客户端设置这些相同的属性,如下所示:

-Djavax.xml.stream.XMLInputFactory=com.ctc.wstx.stax.WstxInputFactory
-Djavax.xml.stream.XMLOutputFactory=com.ctc.wstx.stax.WstxOutputFactory
-Djavax.xml.stream.XMLEventFactory=com.ctc.wstx.stax.WstxEventFactory

关于java - 在 Websphere 上使用 jackson-dataformat-xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59206397/

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