我正在上课,我正在获取对象列表。我正在使用XmlSeeAlso注释来包含列表中存在的类。这是我的班级:
@XmlRootElement
@XmlSeeAlso({BookStore.class,Book.class,Hello.class})
public class ResponseList {
private List<Object> list;
public List<Object> getList() {
return list;
}
public void setList(List<Object> list) {
this.list = list;
}
}
我收到了以下回复:
<responseList>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="book">
<author>Author</author>
<name>The Book</name>
</list>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="bookStore">
<name>The Book Store</name>
<location>US</location>
</list>
</responseList>
我不想在响应中使用xmls:xsi = ....我希望我的输出看起来像这样:
<responseList>
<list>
<author>Author</author>
<name>The Book</name>
</list>
<list>
<name>The Book Store</name>
<location>US</location>
</list>
</responseList>
有没有办法实现这个目标?
答案 0 :(得分:2)
带替换的Jaxb继承可以帮助您(使用@XmlElementRef注释) 欲了解更多信息,请查看以下链接
http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html