2013-03-24 42 views
0

什麼是@xmlseealso jaxb的等價物simplexml。響應蔭解析如下:xmlseealso等價於Simplexml

<things xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="thing"> 
    <val>185</val> 
</things> 
<things xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="thing"> 
    <val>162</val> 
</things> 

我要尋找一個響應這樣的映射

Response.java 

@ElementList 
List<Object> things; 

Thing.java 

@Element 
int val; 

我怎麼能動態地「東西」映射到的「東西」,我會做一個列表在jaxb中使用xmlseealso。 Simplexml中有一種方法嗎?

回答

0

如果你的意思是匹配不同類的,但與共享父元素的列表,那麼解決方案是@ElementListUnion註解。你

@XmlSeeAlso({X.class, Y.class, Z.class}) 

應表示爲:

@ElementListUnion({ 
    @ElementList(entry="x", inline=true, type=X.class), 
    @ElementList(entry="y", inline=true, type=Y.class), 
    @ElementList(entry="z", inline=true, type=Z.class)    
}) 
private List<Superclass> xyz; 

看到http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/ElementListUnion.html