解组名称为“class”的属性时出现问题与 Xstream
我有一个带有名为 class
属性的节点。输入 XML 是:
<Job class="com.test.jobImplementation">
<Priority>1</Priority>
......
</Job>
表示 XML 的 Java 类用 Xstream 注释进行注释,如下所示:
@XStreamAlias("Job")
public static class Job {
@XStreamAsAttribute
@XStreamAlias("class")
private String implementationClass;
@XStreamAlias("Priority")
private Integer priority
}
当我尝试反序列化 XML 时,xstream 失败,返回与问题无关的错误。 (例如,当我用“classs”替换属性名称“class”时,它工作得很好。)
我知道只要 XStream 无法从 XML 中辨别出来,就会使用“class”属性 字段声明确切地表明要使用什么类型,但在这种情况下,我无法修改 XML 输入,并且必须处理属性“class”。
有没有使用 Xstream 解组名为“class”的 XML 属性的解决方法?
I have a node with an attribute named class
. The input XML is :
<Job class="com.test.jobImplementation">
<Priority>1</Priority>
......
</Job>
The Java class which represents the XML is annotated with Xstream annotations is as follows:
@XStreamAlias("Job")
public static class Job {
@XStreamAsAttribute
@XStreamAlias("class")
private String implementationClass;
@XStreamAlias("Priority")
private Integer priority
}
When I try to deserialize the XML, xstream fails returning an error unrelated to the problem. (e.g. when I replace the attribute name "class" by "classs", it works fine.)
I know the "class" attribute is used whenever XStream can't tell from the XML and
the field declaration exactly what type to use, but in this case I can't modify the XML input and I have to process the attribute "class".
Any workaround for unmarshalling an XML attribute with name "class" with Xstream?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 XStream 1.3.1 开始,您可以重新定义这些属性,以允许将名称用于您自己的名称。
http://x-stream.github.io/faq.html#Serialization_system_attributes
Starting with XStream 1.3.1 you can redefine those attributes to allow the names to be used for your own ones.
http://x-stream.github.io/faq.html#Serialization_system_attributes