2013-03-24 38 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