title: How to (un)marshall the value of the root element in a subclass
body: <p>I'm unmarshalling a complex object from XML to Java using JAXB. The problematic part of the XML looks like:</p>
  
  <pre><code>&lt;product&gt;
      &lt;!-- SNIP --&gt;
      &lt;keywords&gt;
          &lt;keyword optionalAttribute="attrValue"&gt;Value&lt;/keyword&gt;
          &lt;keyword&gt;Another value&lt;/keyword&gt;
      &lt;/keywords&gt;
  &lt;/product&gt;
  </code></pre>
  
  <p>I have a Java class for the parent object and for complex attributes, including keywords, with <code>javax.xml.bind.annotation.*</code> annotations.</p>
  
  <pre><code>@XmlRootElement(name = "product")
  @XmlAccessorType(XmlAccessType.NONE)
  public class Product extends Model {
  
      // SNIP
  
      @XmlElementWrapper(name = "keywords")
      @XmlElement(name = "keyword")
      public List&lt;ProductKeyword&gt; keywords;
  }
  </code></pre>
  
  <pre><code>@XmlRootElement(name = "keyword")
  @XmlAccessorType(XmlAccessType.NONE)
  public class ProductKeyword extends Model {
  
      @XmlAttribute(name = "optionalAttribute")
      public String optionalAttribute;
  
      @XmlMixed
      public String keyword;
  
  }
  </code></pre>
  
  <p>The <code>ProductKeyword.keyword</code> field needs to hold the value of the <code>&lt;keyword&gt;</code> element, which is the root element for the subclass. <code>@XmlMixed</code> doesn't seem to induce JAXB to attempt to unmarshall anything into that field.</p>
  
  <p>I believe I need <code>@XmlValue</code>, but that annotation cannot be used on a subclass (unless possibly if the superclass is annotated with <code>@XmlTransient</code>.)</p>
  
  <p>Can anyone suggest a way around this?</p>
  
  <p>Constraints:</p>
  
  <ul>
  <li><p>I can't change the format of the XML.</p></li>
  <li><p>I can't get rid of the <code>Model</code> superclass (required for persistence)</p></li>
  <li><p>I can't modify the superclass (from an external library)</p></li>
  </ul>
  
  <p>Non-constraints:</p>
  
  <ul>
  <li><p>I can, if I need to, add extra fields to the parent or child Java classes. </p></li>
  <li><p>If I can get the values of the keywords into the class in any form or by any means, I can do whatever post-processing I need to get it in the right place/format.</p></li>
  <li><p>It doesn't have to be pretty.</p></li>
  </ul>