title: Change Java's output format for nillable XML elements
body: <p>I'm using java's jaxb to create XML files from java objects.
  The problem I'm facing is the exact opposite as stated here: <a href="https://stackoverflow.com/questions/1364917/linqtoxml-does-not-handle-nillable-elements-as-expected">LinqToXml does not handle nillable elements as expected</a></p>
  
  <p><strong>In short:</strong> I want to properly depict members that are null in the resulting xml file.</p>
  
  <p>I have following member in my class</p>
  
  <pre><code>  @XmlElement (name = "order-detail", nillable = true)
    private String orderDetail;
  </code></pre>
  
  <p>if I marshal an instance of this class, the resulting xml element is</p>
  
  <pre><code>&lt;order-detail xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt;
  </code></pre>
  
  <p>Since also non-technicians are reading, maybe also manipulating, the file, I'd rather have it that way</p>
  
  <pre><code>&lt;order-detail /&gt;
  </code></pre>
  
  <p>since I don't want to confuse them. So how can I achieve this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Using an empty string instead of null</p>
  
  <pre><code>  @XmlElement (name = "order-detail", nillable = true)
    private String orderDetail = "";
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>&lt;order-detail&gt;&lt;/order-detail&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>SSCCE</strong></p>
  
  <pre><code>import javax.xml.bind.JAXBContext;
  import javax.xml.bind.JAXBException;
  import javax.xml.bind.Marshaller;
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
  public class Example
  {
    public static void main(String[] args) throws JAXBException
    {
      Data data = new Data();
      JAXBContext context = JAXBContext.newInstance(Data.class);
      Marshaller m = context.createMarshaller();
      m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      m.marshal(data, System.out);
    }
  
    @XmlRootElement(name = "data")
    static class Data
    {
      private String orderDetail;
  
      @XmlElement (name = "order-detail", nillable = true)
      public String getOrderDetail()                  { return orderDetail;             }
      public void setOrderDetail(String orderDetail)  { this.orderDetail = orderDetail; }
    }
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;data&gt;
      &lt;order-detail xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt;
  &lt;/data&gt;
  </code></pre>