title: JAXB Avoid saving default values
body: <p>Is there any way to make JAXB not save fields which values are the default values specified in the @Element annotations, and then make set the value to it when loading elements from XML that are null or empties? An example:</p>
  
  <pre><code>class Example
  {
      @XmlElement(defaultValue="default1")
      String prop1;
  }
  
  Example example = new Example();
  example.setProp1("default1");
  jaxbMarshaller.marshal(example, aFile);
  </code></pre>
  
  <p>Should generate:</p>
  
  <pre><code>&lt;example/&gt;
  </code></pre>
  
  <p>And when loading</p>
  
  <pre><code>Example example = (Example) jaxbUnMarshaller.unmarshal(aFile);
  assertTrue(example.getProp1().equals("default1"));
  </code></pre>
  
  <p>I am trying to do this in order to generate a clean XML configuration file, and make it better readable and smaller size.</p>
  
  <p>Regars and thanks in advance.</p>