我有這樣的XML:如何解析xml元素爲原始類型?
<order>
<id_address_delivery>4</id_address_delivery>
</order>
和Java類
@JacksonXmlRootElement(localName = "order")
public static class Order
{
@JacksonXmlProperty(localName = "id_address_delivery")
public String id_address_delivery;
}
當我試着使用代碼來解析XML:
XmlMapper XmlMapper = new XmlMapper()
XmlMapper.readValue(xml, Order.class);
我得到的錯誤:無法反序列化實例java.lang.String out of START_OBJECT token
如何更正deserialize xml元素爲原始類型?
也'XmlMapper XmlMapper =新XmlMapper()'沒有意義。它至少應該是'xmlMapper'(第一個字母小寫)和'xmlMapper.readValue(..)'。 – Timo