[英]Unmarshall xml file, UnrecognizedPropertyException: Unrecognized field “”
I was wondering if somebody can help me out. 我想知道是否有人可以帮助我。 I created a small maven project so you can easily run the test. 我创建了一个小Maven项目,以便您可以轻松运行测试。 For testing you can run the JUnit test UnmarshalTest.unmarshalResponse() which fails with a exception. 为了进行测试,您可以运行JUnit测试UnmarshalTest.unmarshalResponse(),该测试会失败并发生异常。
I'm trying to read a value from a xml element with an attribute but somehow I'm not able to to that. 我正在尝试从具有属性的xml元素读取值,但是以某种方式我无法做到这一点。 Any idea why? 知道为什么吗?
XML looks like: XML看起来像:
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<id_lang xlink:href="http://prestashop.local/api/languages/1">57</id_lang>
</prestashop>
Thx a lot 多谢
/david /大卫
[Update] Sorry, I prepared already the code but forgot to upload it ... https://drive.google.com/open?id=1t99zBxN7juA9RgNhS6S9UCCFSYxksnXW [更新]抱歉,我已经准备好代码了,但是忘了上传它... https://drive.google.com/open?id=1t99zBxN7juA9RgNhS6S9UCCFSYxksnXW
The full message coming back is such as: 返回的完整消息如下:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class com.smooth.systems.test.TagValue), not marked as ignorable (2 known properties: "idLang", "href"])
at [Source: (File); line: 3, column: 76] (through reference chain: com.smooth.systems.test.TestWrapper["id_lang"]->com.smooth.systems.test.TagValue[""])
Which points to the 76
in the body of the <id_lang>
element in the example above - hence the missing field name. 在上面的示例中,它指向<id_lang>
元素主体中的76
,因此缺少字段名称。
(It is line 3, there's another <?xml ... ?>
declaration line not seen in the sample xml). (这是第3行,还有另外一个<?xml ... ?>
声明行在示例xml中未显示)。
Switching the @XmlValue
annotation to @JacksonXmlText
on the owning TagValue
class seems to work better. 切换@XmlValue
注释@JacksonXmlText
上拥有TagValue
类似乎更好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.