Title: Marshalling null objects

I apologize if this is discussed elsewhere; I tried finding a solution to my problem, but to no avail.

When marshalling to produce xml from my objects, if a String is null, then a NullPointerException is thrown.  I found that if I set usage="optional", then the exception went away, but an empty tag was not output to the xml.  I thought that if I then provided a default value, then that default would be used when a null String was encountered. 

My mapping xml looks like this:
<value name="IssueAge" field="issueAge" usage="optional" default="" />

However, setting a default here doesn't seem to work; I still don't get an empty tag.  Due to requirements, I must include an empty tag if the data is not set (e.g. it is not an option for me to not output a tag if no value exists).

Am I missing something here or is jibx currently not able to do this?  If this functionality doesn't exist, I would be happy to code this if there is interest.

If necessary, I can work around this problem by setting all of my String objects in the class files to an empty string, but this is not preferred.  If I do this, then it will output <IssueAge></IssueAge>, which leads me to my next question.  Is there a way to have jibx output the consolidated form of an empty element (<IssueAge />)?

Thank you in advance,

Paul

*************************************
Paul Poole
J2EE Developer
Business Process Automation
Conseco
Carmel, IN 46032
*************************************

Reply via email to