title: Representing element as boolean with JAXB?
body: <p>We have this XML:</p>
  
  <pre><code>  &lt;Summary&gt;
       &lt;ValueA&gt;xxx&lt;/ValueA&gt;
       &lt;ValueB/&gt;
    &lt;/Summary&gt;
  </code></pre>
  
  <p><code>&lt;ValueB/&gt;</code> will never have any attributes or inner elements.  It's a boolean type element - it exists (true) or it doesn't (false).</p>
  
  <p>JAXB generated a Summary class with a String valueA member, which is good.  But for ValueB, JAXB generated a ValueB inner class and a corresponding member:</p>
  
  <pre><code>@XmlElement(name = "ValueB")
  protected Summary.ValueB valueB;
  </code></pre>
  
  <p>But what I'd like is a <code>boolean</code> member and <em>no</em> inner class: </p>
  
  <pre><code>@XmlElement(name = "ValueB")
  protected boolean valueB;
  </code></pre>
  
  <p>How can you do this?  </p>
  
  <p>I'm not looking to regenerate the classes, I'd like to just make the code change manually.</p>
  
  <hr>
  
  <p><strong>Update</strong>: In line with the accepted answer, we created a new method returning the boolean value conditional on whether valueB == null.  </p>
  
  <p>As we are using Hibernate, we annotated valueB with <code>@Transient</code> and annotated the boolean getter with Hibernate's <code>@Column</code> annotation.  </p>