title: JAXB/Jackson: Sequence of two elements without parent tag
body: <p><strong>Update</strong>: Looking for a Jackson <strong><em>or</em></strong> JAXB solution.</p>
  
  <p>After researching a bit about behavior of Jackson, I found that Jackson will always use a wrapper for collections. So probably what I need is not possible to do with Jackson. Hence, added JAXB to title.</p>
  
  <hr>
  
  <p><strong>Original Question</strong></p>
  
  <p>I need to create POJO for following XML pattern.</p>
  
  <pre><code>&lt;ABWrap&gt;
      &lt;A&gt;&lt;/A&gt;
      &lt;B&gt;&lt;/B&gt;
      &lt;A&gt;&lt;/A&gt;
      &lt;B&gt;&lt;/B&gt;
      ...
      ... n times
  &lt;/ABWrap&gt;
  </code></pre>
  
  <p>I've tried following POJOs. But these are not generating desired result.</p>
  
  <pre><code>class AB {
      @JacksonXmlProperty(localName = "A")
      private String A;
      @JacksonXmlProperty(localName = "B")
      private String B;
  }
  
  @JacksonXmlRootElement(localName = "ABWrap")
  class ABWrap {
      @JacksonXmlElementWrapper(useWrapping = false)
      private AB[] ab = new AB[n];
  }
  </code></pre>
  
  <p>I need to maintain the condition that pair of <code>&lt;A&gt;&lt;/A&gt;</code> and <code>&lt;B&gt;&lt;/B&gt;</code> should come together. Sequence of elements is important.<br>
  Following pattern will not work in my case:</p>
  
  <pre><code>&lt;ABWrap&gt;
      &lt;A&gt;&lt;/A&gt;
      &lt;A&gt;&lt;/A&gt;
      ...
      ... n times
      &lt;B&gt;&lt;/B&gt;
      &lt;B&gt;&lt;/B&gt;
      ...
      ... n times
  &lt;/ABWrap&gt;
  </code></pre>
  
  <p>I have been able to achieve second one. But I've not been able to figure out a way to generate the first pattern.</p>
  
  <hr>
  
  <p><strong>Update on @mart's answer</strong>:</p>
  
  <p>I defined <code>ABWrap</code>, <code>ABInterface</code> and <code>A</code> as follows:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlRootElement(name = "ABWrap")
  public class ABWrap {
      @XmlElements({@XmlElement(name = "A", type = A.class), @XmlElement(name = "B", type = B.class)})
      private List&lt;ABInterface&gt; ab;
  }
  
  public interface ABInterface { }
  
  public class A implements ABInterface {
      @XmlValue
      private String a;
  }
  </code></pre>
  
  <p><code>B</code> is defined similar to <code>A</code>. </p>
  
  <p>main method is as follows:</p>
  
  <pre><code>public class Application {
  
      public static void main(final String[] args) throws JAXBException {
  
          JAXBContext jaxbContext = JAXBContext.newInstance(ABWrap.class);
          Marshaller marshaller = jaxbContext.createMarshaller();
          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
          A a = new A("a");
          B b = new B("b");
          ABWrap abWrap = new ABWrap(Arrays.asList(a, b));
          marshaller.marshal(abWrap, System.out);
      }
  }
  </code></pre>
  
  <p>But this solution failed with following error: (<code>jaxbpoc</code> is project name)</p>
  
  <pre><code>If a class has @XmlElement property, it cannot have @XmlValue property.
  this problem is related to the following location:
      at private java.lang.String ...jaxbpoc.A.a
      at ...jaxbpoc.A
      at private java.util.List ...jaxbpoc.ABWrap.ab
      at ...jaxbpoc.ABWrap
  this problem is related to the following location:
      at public java.lang.String ...A.getA()
      at ...jaxbpoc.A
      at private java.util.List ...jaxbpoc.ABWrap.ab
      at ...jaxbpoc.ABWrap
  If a class has @XmlElement property, it cannot have @XmlValue property.
  this problem is related to the following location:
      at private java.lang.String ...jaxbpoc.B.b
      at ...jaxbpoc.B
      at private java.util.List ...jaxbpoc.ABWrap.ab
      at ...jaxbpoc.ABWrap
      ....
      ....
  Class has two properties of the same name "a"
  this problem is related to the following location:
      at public java.lang.String ...jaxbpoc.A.getA()
      at ...jaxbpoc.A
      at private java.util.List ...jaxbpoc.ABWrap.ab
      at ...jaxbpoc.ABWrap
  this problem is related to the following location:
      ....
      ....
  </code></pre>