我正在使用 eBay 的查找服务,除了解析 unitPrice 之外,一切正常。它说here :
eBay uses the UnitType and UnitQuantity
所以在我的 UnitPriceInfo.java 中我有这个:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UnitPriceInfo", propOrder = { "type", "quantity", "any" })
public class UnitPriceInfo
{
@XmlElement(name = "UnitType")
protected String type;
@XmlElement(name = "UnitQuantity")
protected Double quantity;
@XmlAnyElement(lax = true)
protected List<Object> any;
但是,UnitPriceInfo
对象仍然被实例化,但它们的类型和数量字段始终为空。
我需要将类型从 String 和 Double 更改为 UnitType
和 UnitQuantity
吗?如果没有,问题出在哪里?
最佳答案
这些元素被命名为type
和quantity
,如下所示:
<unitPrice>
<quantity> double </quantity>
<type> string </type>
</unitPrice>
您应该将注释更改为 @XmlElement(name="type")
和 @XmlElement(name="quantity")
。
关于java - 无法解析复杂类型的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24888135/