2

I am having a class in which I am getting list of objects. I am using XmlSeeAlso annotation to include the classes which are present in the list. Here is my class:

@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;
    }

}

I am getting following response:

<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>

I don't want this xmls:xsi=... in the response. I want my output to look like this:

<responseList>
  <list>
    <author>Author</author>
    <name>The Book</name>
  </list>
  <list>
    <name>The Book Store</name>
    <location>US</location>
  </list>
</responseList>

Is there any way to achieve this ?

Prats
  • 1,515
  • 6
  • 16
  • 30

1 Answers1

2

Jaxb inheritance with substitution may help you(using @XmlElementRef annotation).
For more information please look into the below link

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

Prabhaker A
  • 8,317
  • 1
  • 18
  • 24