title: Marshall xsd:any content as string with JAXB
body: <p>I am searching for an solution for the following problem.</p>
  <p>I have xml content which looks like this:</p>
  <pre><code>&lt;my:Chapter&gt;
       &lt;my:Number&gt;8.1.&lt;/my:Number&gt;
       &lt;my:Title&gt;chapter title&lt;/my:Title&gt;
       &lt;my:Text&gt;
           &lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;dsfsdfsda sadfa ef aw&lt;/div&gt;
           &lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;aawfwa ef&lt;/div&gt;
           &lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;aw&lt;/div&gt;
       &lt;/my:Text&gt;
   &lt;/my:Chapter&gt;
  </code></pre>
  <p>The node &quot;Text&quot; can contain any xhtml elements. When marshalling this xml to java class, I need this text content as it is as a string.</p>
  <p>The XSD for that element looks like this:</p>
  <pre><code>&lt;xsd:element name=&quot;Text&quot;&gt;
      &lt;xsd:complexType mixed=&quot;true&quot;&gt;
          &lt;xsd:sequence&gt;
              &lt;xsd:any minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot; namespace=&quot;http://www.w3.org/1999/xhtml&quot;
                       processContents=&quot;lax&quot;/&gt;
          &lt;/xsd:sequence&gt;
      &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
  </code></pre>
  <p>The JAXB class generation is producing the following:</p>
  <pre><code>@XmlRootElement(name = &quot;Chapter&quot;)
  public class Chapter {
  
      @XmlElement(name = &quot;Number&quot;)
      protected String number;
      @XmlElement(name = &quot;Title&quot;)
      protected String title;
      @XmlElement(name = &quot;Text&quot;)
      protected Text text;
      
      getters and setters ...
  
  }
  
  
  @XmlRootElement(name = &quot;Text&quot;)
  public class Text {
  
      @XmlMixed
      @XmlAnyElement(lax = true)
      protected List&lt;Object&gt; content;
  
      public List&lt;Object&gt; getContent() {
          if (content == null) {
              content = new ArrayList&lt;Object&gt;();
          }
          return this.content;
      }
  
  }
  </code></pre>
  <p>Currently all child elements of the Text element are marshalled as <code>List&lt;Object&gt;</code>, which needs to be unmarshalled again to get the xhtml content as string. This is in my eyes a waste of processing time.</p>
  <p>What I want is, that the xhtml text content is just taken as a single String. Like so:</p>
  <pre><code>@XmlRootElement(name = &quot;Chapter&quot;)
  public class Chapter {
  
      @XmlElement(name = &quot;Number&quot;)
      protected String number;
      @XmlElement(name = &quot;Title&quot;)
      protected String title;
      @XmlElement(name = &quot;Text&quot;)
      protected String text;
      
      getters and setters ...
  
  }
  </code></pre>
  <p>I already have setup some xjb bindings and XmlAdapter for some other cases and expect that also as a solution for this, but I was not successful to achieve what I want so far.</p>
  <p>The XML files can not be changed, because it is already production data. XSD and bindings are under my control and can be changed.</p>
  <p>Does anyone have an idea?</p>