title: Marshalled XML has no children when using mixed types
body: <p>I am trying to unmarshall a <a href="http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_7.5.html" rel="nofollow noreferrer">DICOM Sequence VR type</a> which is stored in the database as an XML CLOB. As per the standard, the sequence can contain properties as well as sequences as children. An example for reference is the <a href="https://dicom.innolitics.com/ciods/enhanced-sr/sr-document-content/0040a730" rel="nofollow noreferrer">Content Sequence</a> attribute.</p>
  
  <p>As a result, I am using <code>@XmlMixed</code> in my JAXB DTOs to handle the case where the child property may also be a sequence. However, on marshalling the unmarshalled XML, the resultant output is just the root element without the children.</p>
  
  <p>Below is my input XML representing the aforementioned Content Sequence.</p>
  
  <pre><code>&lt;Root&gt;
    &lt;ps&gt;
      &lt;p name="0040A010" vt="8"&gt;HAS CONCEPT MOD&lt;/p&gt;
      &lt;p name="0040A040" vt="8"&gt;CODE&lt;/p&gt;
      &lt;p name="0040A043" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00080100" vt="8"&gt;121049&lt;/p&gt;
          &lt;p name="00080102" vt="8"&gt;DCM&lt;/p&gt;
          &lt;p name="00080104" vt="8"&gt;Language of Content Item and Descendants
          &lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
      &lt;p name="0040A168" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00080100" vt="8"&gt;eng&lt;/p&gt;
          &lt;p name="00080102" vt="8"&gt;ISO639_2&lt;/p&gt;
          &lt;p name="00080104" vt="8"&gt;English&lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
    &lt;/ps&gt;
    &lt;ps&gt;
      &lt;p name="0040A010" vt="8"&gt;HAS OBS CONTEXT&lt;/p&gt;
      &lt;p name="0040A040" vt="8"&gt;CODE&lt;/p&gt;
      &lt;p name="0040A043" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00080100" vt="8"&gt;121005&lt;/p&gt;
          &lt;p name="00080102" vt="8"&gt;DCM&lt;/p&gt;
          &lt;p name="00080104" vt="8"&gt;Observer Type&lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
      &lt;p name="0040A168" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00080100" vt="8"&gt;121006&lt;/p&gt;
          &lt;p name="00080102" vt="8"&gt;DCM&lt;/p&gt;
          &lt;p name="00080104" vt="8"&gt;Person&lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
    &lt;/ps&gt;
    &lt;ps&gt;
      &lt;p name="0040A010" vt="8"&gt;HAS OBS CONTEXT&lt;/p&gt;
      &lt;p name="0040A040" vt="8"&gt;PNAME&lt;/p&gt;
      &lt;p name="0040A043" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00080100" vt="8"&gt;121008&lt;/p&gt;
          &lt;p name="00080102" vt="8"&gt;DCM&lt;/p&gt;
          &lt;p name="00080104" vt="8"&gt;Person Observer Name&lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
      &lt;p name="0040A123" vt="8"&gt;IMAGE&lt;/p&gt;
    &lt;/ps&gt;
    &lt;ps&gt;
      &lt;p name="00081199" vt="8"&gt;
        &lt;ps&gt;
          &lt;p name="00081150" vt="8"&gt;1.2.840.10008.5.1.4.1.1.4&lt;/p&gt;
          &lt;p name="00081155" vt="8"&gt;1.3.6.1.4.1.5962.99.1.3923360762.207819601.1541521685498.13.0
          &lt;/p&gt;
          &lt;p name="00081199" vt="8"&gt;
            &lt;ps&gt;
              &lt;p name="00081150" vt="8"&gt;1.2.840.10008.5.1.4.1.1.11.1&lt;/p&gt;
              &lt;p name="00081155" vt="8"&gt;1.2.840.114356.2019.12.115.113.18.116.1508.6
              &lt;/p&gt;
            &lt;/ps&gt;
          &lt;/p&gt;
          &lt;p name="00750010" vt="8"&gt;GEIIS_IW&lt;/p&gt;
          &lt;p name="007510A1" vt="8"&gt;1&lt;/p&gt;
        &lt;/ps&gt;
      &lt;/p&gt;
      &lt;p name="0040A010" vt="8"&gt;CONTAINS&lt;/p&gt;
      &lt;p name="0040A040" vt="8"&gt;IMAGE&lt;/p&gt;
    &lt;/ps&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>And below are the classes used to map bind the above structure:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlRootElement(name = "p")
  public class Property
  {
     @XmlElementRef(name = "ps", type = PropertySequence.class, required = false)
     @XmlMixed
     protected List&lt;Object&gt; content;
  
     @XmlAttribute(name = "name", required = true)
     protected String name;
  
     public List&lt;Object&gt; getContent()
     {
        if (content == null)
        {
           content = new ArrayList&lt;Object&gt;();
        }
  
        return this.content;
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String value)
     {
        this.name = value;
     }
  }
  </code></pre>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD) 
  @XmlRootElement(name = "ps") 
  public class PropertySequence 
  { 
     protected List&lt;Property&gt; property; 
  
     public List&lt;Property&gt; getProperty() 
     { 
        if (property == null) 
        { 
           property = new ArrayList&lt;Property&gt;(); 
        } 
  
        return this.property; 
     } 
  }
  </code></pre>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlRootElement(name = "Root")
  public class Root
  {
     @XmlElement(required = true)
     protected List&lt;PropertySequence&gt; propertySequence;
  
     public List&lt;PropertySequence&gt; getPropertySequence()
     {
        if (propertySequence == null)
        {
           propertySequence = new ArrayList&lt;PropertySequence&gt;();
        }
  
        return this.propertySequence;
     }
  }
  </code></pre>
  
  <p>On running the below test code, the output XML after unmarshalling and subsequent marshalling, the output is only the root tag.</p>
  
  <pre><code>try (InputStream xmlStream = Launcher.class.getResourceAsStream("/PropertySequence.xml")) 
  { 
     JAXBContext context = JAXBContext.newInstance(Root.class); 
  
     Unmarshaller unmarshaller = context.createUnmarshaller(); 
     Root root = (Root) unmarshaller.unmarshal(xmlStream); 
  
     Marshaller marshaller = context.createMarshaller(); 
     marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
     marshaller.marshal(root, System.out);
  } 
  catch (IOException | JAXBException e) 
  { 
     e.printStackTrace(); 
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;Root/&gt;
  </code></pre>