JAXB无法解析复杂类型的属性

时间:2014-07-22 13:00:19

标签: java web-services jaxb ebay

我正在使用eBay的查找服务,除了解析unitPrice之外,一切正常。它说here

  

eBay使用UnitType和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对象仍然被实例化,但它们总是将类型和数量字段都归零。

我是否需要将字符串和Double的类型更改为UnitTypeUnitQuantity?如果没有,问题是什么?

2 个答案:

答案 0 :(得分:0)

元素名为typequantity,如下所示:

  <unitPrice>
    <quantity> double </quantity>
    <type> string </type>
  </unitPrice>

您应将注释更改为@XmlElement(name="type")@XmlElement(name="quantity")

答案 1 :(得分:-1)

是否可以将类名从UnitPriceInfo更改为“unitPrice”或为类名提供带注释的名称“unitPrice”。