【发布时间】:2020-03-29 06:41:54
【问题描述】:
我在 Spring 上下文中使用 XStream 时遇到问题。
如果我们在 pom 中导入 xstream 依赖项,c.t.x.XStream.addImplicitCollection(Class ownerType, String fieldName, String itemFieldName, Class itemType) 方法将无法正常工作,但如果我们导入 xstream 源代码并在 pom 中排除相关依赖项,则它确实有效。
我们使用了以下依赖项的版本:
-
xstream:1.4.11.1
- spring-boot-dependencies:2.1.2.RELEASE
在pom.xml 中使用xstream 的依赖项测试fromXml 我们有以下错误:
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: Duplicate field point
---- Debugging information ----
message : Duplicate field point
field : point
class : c.g.m.r.d.Child
required-type : c.g.m.r.d.Child
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /root/child/point[2]
line number : 1
class[1] : c.g.m.r.d.Root
required-type[1] : c.g.m.r.d.Root
version : 1.4.11.1
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$3.add(AbstractReflectionConverter.java:287)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:457)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:499)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:425)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1487)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1467)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1338)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1329)
使用 xstream 的源代码测试 fromXml 确实可以正常工作。
在 Spring 上下文中使用 JUnit 测试 fromXml 确实可以正常工作。
XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<point label="...">
<date>...</date>
<value>...</value>
</point>
<point label="...">
<date>...</date>
<value>...</value>
</point>
</child>
</root>
你有什么想法吗?
【问题讨论】:
标签: java xml spring spring-boot xstream