users@jaxb.java.net

Remove empty optional elements from xml

From: Krzysztof Sobkowiak <krzys.sobkowiak_at_gmail.com>
Date: Wed, 27 Nov 2013 11:41:34 +0100

Hi

I have a functionality which sends a lot of xml data generated using
JAXB from structures filled with data in business code. The generated
xml contains many empty elements even if the attribute is optional, e.g.
somebody sets empty string instead of null or sets empty data structure.
I cannot force the changes in the business code, I cannot change the
xsds but I can eventually change the generated java classes using
binding customization.

Is there any functionality which allows me to clean up the empty
optional elements before/while/after marshalling? If not, is there any
code in JAXB I could look at/I could reuse and implement a functionality
which traverses the generated structure and performs the cleanup?

I use currently the version 2.2.4-1 of JAXB implementation.

Best regards
Krzysztof