title: How do Inheritance and JAXB work together?
body: <pre><code>public abstract class Parent&lt;T&gt; {
      protected List&lt;T&gt; list;
  
      @XmlTransient   //Question why do we have to give this here?
      public abstract List&lt;T&gt; getList();
      public abstract void setList(List&lt;T&gt; list);
  }
  
  @XmlRootElement(name = "child1")
  class Child1 extends Parent&lt;ExtendedElement1&gt;{
      @Override
      public void setList(List&lt;ExtendedElement1&gt; list){
          this.list = list;
      }
  
      @Override
      @XmlElementWrapper(name = "child1-list")
      @XmlElement(name = "child-list-element")
      public List&lt;ExtendedElement1&gt; getList(){
          return this.list;
      }
  }
  
  @XmlRootElement(name = "child2")
  class Child2 extends Parent&lt;ExtendedElement2&gt;{
      @Override
      public void setList(List&lt;ExtendedElement2&gt; list){
          this.list = list;
      }
  
      @Override
      @XmlElementWrapper(name = "child1-list")
      @XmlElement(name = "child-list-element")
      public List&lt;ExtendedElement2&gt; getList(){
          return this.list;
      }
  }
  
  
  class Element{
      @XmlElement(name = "integer", type = int.class)
      private int i = 2;
  }
  
  class ExtendedElement1 extends Element{
      @XmlElement(name = "extended-element1-str", type = String.class)
      private String str = "hello";
  }
  
  class ExtendedElement2 extends Element{
      @XmlElement(name = "extended-element2-str", type = String.class)
      private String str1 = "hello_there";
  }
  </code></pre>
  
  <p>As I have shown in the example when I <strong>remove</strong> the <code>@XmlTransient</code> from the <code>Parent</code> class <code>getList()</code> method, following xml is marshalled:</p>
  
  <pre><code>&lt;child1&gt;
  &lt;!-- List is serialized 2 times --&gt;
      &lt;list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="extendedElement1"&gt;
          &lt;integer&gt;2&lt;/integer&gt;
          &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
      &lt;/list&gt;
      &lt;list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="extendedElement1"&gt;
          &lt;integer&gt;2&lt;/integer&gt;
          &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
      &lt;/list&gt;
      &lt;list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="extendedElement1"&gt;
          &lt;integer&gt;2&lt;/integer&gt;
          &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
      &lt;/list&gt;
      &lt;child1-list&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
      &lt;/child1-list&gt;
  &lt;/child1&gt;
  </code></pre>
  
  <p>But when I <strong>add</strong> the <code>@XmlTransient</code> annotation, as in the example the xml is serialized with only <strong>ONE</strong> list as required. </p>
  
  <pre><code>&lt;child1&gt;
      &lt;child1-list&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
          &lt;child-list-element&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;extended-element1-str&gt;hello&lt;/extended-element1-str&gt;
          &lt;/child-list-element&gt;
      &lt;/child1-list&gt;
  &lt;/child1&gt;
  </code></pre>
  
  <p>So please can someone explain me why is it required to give <code>@XmlTransient</code> in Parent Class getter method? How does inheritance and JAXB inter-relate for these cases?</p>