I use JAXB to create XML messages. The XML I need to create is (for the sake of simplicity):
I wanted the same thing, effectively rather than
during the xml serialization process.
Since a null value - rather than an empty string - will produce the correct result, I modified my setter method to set the value explicitly to null:
public void setHeader(String header) {
this.header = "".equals(header) ? null : header;
}