我想知道是否有可能将xml元素解组到多个pojos。例如:JAXB unmarshall到多个pojo的
用于XML:
<type>
<id>1</id>
<cost>12</cost>
<height>15</height>
<width>13</width>
<depth>77</depth>
</type>
Item类
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name="type")
public class Item {
private Integer id;
private Double cost;
@XmlElement(name="id")
public Integer getId(){
return id;
}
@XmlElement(name="cost")
public Double getCost(){
return cost
}
}
ItemDimensions类
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name="type")
public class ItemDimensions {
private Integer height;
private Integer width;
private Integer depth;
@XmlElement(name="height")
public Integer getHeight(){
return height;
}
@XmlElement(name="width")
public Integer getWidth(){
return width;
}
@XmlElement(name="depth")
public Integer getDepth(){
return depth;
}
}
我曾尝试使用许多由产生JAXB映射来完成类似的东西Netbeans 6.9和一些测试类,但现在已经得到了。有谁知道这是否可以在没有任何中介对象的情况下完成?
AFAIK您将不得不自己创建ItemDimensions对象。例如返回新的ItemDimensions(高度,宽度,深度)。 – nabeelmukhtar 2011-04-25 15:13:45