2

我有一个类,我在其中获取对象列表。我正在使用 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>

有没有办法做到这一点?

4

1 回答 1

2

带有替换的 Jaxb 继承可能会对您有所帮助(使用 @XmlElementRef 注释)。
欲了解更多信息,请查看以下链接

http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html

于 2013-07-12T12:09:39.313 回答