users@jaxb.java.net

Re: Remove empty optional elements from xml

From: Krzysztof Sobkowiak <krzys.sobkowiak_at_gmail.com>
Date: Wed, 27 Nov 2013 13:39:12 +0100

Yes, I think about it. When I walk the object I can check, whether the
attributes have the jaxb annotations and check whether the attribute is
required or not. I wanted to know first, whether there is any other
solution integrated with JAXB.

With the xslt transformation I'll have problem to check, whether the
attribute is required. We have situations where attribute is required
but no data should be sent (business specification...). In this case for
example an empty string is set in the business code and empty elements
are created and can not be removed.

On 27.11.2013 12:45, Wolfgang Laun wrote:
> Isn't walking the object tree (prior to calling marshal) and pruning
> and modifying
> object feasible?
>
> Or applying a transformation to the resulting XML before it is sent on the wire?
>
> -W
>
>
> On 27/11/2013, Krzysztof Sobkowiak <krzys.sobkowiak_at_gmail.com> wrote:
>> 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
>>