title: XMLEncoder produces less human readable XML in java 7 compared to java 6
body: <p>Here is a simple example demonstrating the problem:</p>
  
  <p>Consider the two bean classes Alpha and Beta:</p>
  
  <pre><code>public class Alpha {
      private String name;
      private Beta beta;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Beta getBeta() {
          return beta;
      }
  
      public void setBeta(Beta beta) {
          this.beta = beta;
      }
  }
  
  
  public class Beta {
      private Alpha alpha;
  
      public Alpha getAlpha() {
          return alpha;
      }
  
      public void setAlpha(Alpha alpha) {
          this.alpha = alpha;
      }
  }
  </code></pre>
  
  <p>Then instances of Alpha and Beta are created, and the Alpha object is written to XML:</p>
  
  <pre><code>Alpha alpha = new Alpha();
  Beta beta = new Beta();
  
  alpha.setBeta(beta);
  alpha.setName("Rama");
  beta.setAlpha(alpha);
  
  XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("file.xml")));
  encoder.writeObject(alpha);
  encoder.close();
  </code></pre>
  
  <p>In java 6 this results in the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;java version="1.6.0_24" class="java.beans.XMLDecoder"&gt;
   &lt;object id="Alpha0" class="dk.kruger.Alpha"&gt;
    &lt;void property="beta"&gt;
     &lt;object class="dk.kruger.Beta"&gt;
      &lt;void property="alpha"&gt;
       &lt;object idref="Alpha0"/&gt;
      &lt;/void&gt;
     &lt;/object&gt;
    &lt;/void&gt;
    &lt;void property="name"&gt;
     &lt;string&gt;Rama&lt;/string&gt;
    &lt;/void&gt;
   &lt;/object&gt;
  &lt;/java&gt;
  </code></pre>
  
  <p>But in java 7 the result is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;java version="1.7.0_07" class="java.beans.XMLDecoder"&gt;
   &lt;object class="dk.kruger.Alpha" id="Alpha0"&gt;
    &lt;void property="beta"&gt;
     &lt;object class="dk.kruger.Beta"&gt;
      &lt;void property="alpha"&gt;
       &lt;object idref="Alpha0"&gt;
        &lt;void property="name"&gt;
         &lt;string&gt;Rama&lt;/string&gt;
        &lt;/void&gt;
       &lt;/object&gt;
      &lt;/void&gt;
     &lt;/object&gt;
    &lt;/void&gt;
   &lt;/object&gt;
  &lt;/java&gt;
  </code></pre>
  
  <p>The XML generated by java 7 is much less human readable than the java 6 XML (especially, of course, for more complex examples). In the example above, the java 7 encoder defines the "name" property of "alpha" inside the definition of "beta", because "beta" also has a reference to "alpha". This behavior may result in deeply nested and ugly XML.</p>
  
  <p>Is there a way to make the XML encoder in java 7 produce XML in java 6 style?</p>