XStream omit empty tags

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

XStream omit empty tags

zbeedatm
This post has NOT been accepted by the mailing list yet.
Hi,

I have the following code:
<nabble_embed>XStream xStream = new XStream() { protected MapperWrapper wrapMapper(MapperWrapper next) { return new UpperCaseMapper(next) { @SuppressWarnings("unchecked") public boolean shouldSerializeMember(Class definedIn, String fieldName) { if (definedIn != Object.class) { return super.shouldSerializeMember(definedIn, fieldName); } return false; } }; } };</nabble_embed>

The result is:
<nabble_embed> <MessageHeaderX2> <MessageIDX2>15131316545135165165</MessageIDX2> <MessageCreatorX2>Message Creator</MessageCreatorX2> <MessageReasonX2>Notification Reason</MessageReasonX2> <NotificationLevelX2>Level</NotificationLevelX2> </MessageHeaderX2> <MessageBodyX2> <HooliganInfoX2> <b><ServiceIdX2></ServiceIdX2></b> <IsHooliganX2>true</IsHooliganX2> <HoursToBlockX2>10</HoursToBlockX2> </HooliganInfoX2> </MessageBodyX2></nabble_embed>

As you can see the ServiceId is empty.
I need to omit empty tags from returned message.

Can I do it from inside this method: shouldSerializeMember() by checking if the field value is empty?
How can it accomplished?

Regards.