title: How to generate self-closing tag <tag/> for empty element in XML using JAXB
body: <p>A sample code with <code>jaxb-api</code> <code>2.3.1</code> and Java 8 using <code>StringWriter</code> for <code>jaxbMarshaller</code>:</p>
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = &quot;&quot;, propOrder = {
      &quot;currencyCode&quot;,
      &quot;discountValue&quot;,
      &quot;setPrice&quot;
  })
  @XmlRootElement(name = &quot;countryData&quot;)
  public class CountryData {
      protected String currencyCode;
      protected String discountValue = &quot;&quot;;
      protected String setPrice = &quot;&quot;;
  
      // setters and setters
  }
  </code></pre>
  <p>When I marshal the entity to a XML string with:</p>
  <pre><code>StringWriter sw = new StringWriter();
  jaxbMarshaller.marshal(countryDataObject, sw);
  sw.toString();
  </code></pre>
  <p>How to get expected result for empty values?</p>
  <pre><code>&lt;currencyCode&gt;GBP&lt;/currencyCode&gt;
  &lt;discountValue/&gt;
  &lt;setPrice/&gt;
  </code></pre>
  <p>Actual output:</p>
  <pre><code>&lt;currencyCode&gt;GBP&lt;/currencyCode&gt;
  &lt;discountValue&gt;&lt;/discountValue&gt;
  &lt;setPrice&gt;&lt;/setPrice&gt;
  </code></pre>