Yes, a post-set method will allow you to check for a null collection reference (which will occur when the <list> element is missing from the input XML) and replace it with an empty List instance.
- Dennis Dennis M. Sosnoski SOA and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 Sunil Mazimdar wrote: > > Thanks for the reply. Actually the class is a pojo, with properties, > getters and setters. I tried using “field” attribute instead of > “get-method and set-method” in the collections element that did not > solve it. I still get a null reference for the collection during > unmarshalling when the element “list” is missing from the input xml. > > <binding> > > <mapping name=”A” class=”a”> > > <structure > > name="list" > > usage="optional" > > test-method=" testListIsNullOrEmpty"> > > <collection > > field=”list” > > factory=”package.Factory.listFactory” <!—this method creates and > returns an ArrayList à > > item-type=”item” > > </structure> > > </mapping> > > <mapping ---- for item --/> > > </binding> > > Regards, > > Sunil > > ------------------------------------------------------------------------ > > *From:* [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] *On Behalf Of > *Stephan Bourges > *Sent:* Thursday, March 29, 2007 1:27 PM > *To:* JiBX users > *Subject:* Re: [jibx-users] Null Collection Fields > > From what I could read, you will need to use post-set on your > collection. In the post set method, you will check if the object > attribute is set to null and adjust accordingly. Since I didn't see > any field attribute in the XML, I'm not sure if this would work since > it looks like your A class extends from ArrayList or something. I have > to say, that I didn't need to implement any post-set in my own > application, so this is only from doc. > > ------------------------------------------------------------------------ > > *From:* [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] *On Behalf Of *Sunil > Mazimdar > *Sent:* Thursday, March 29, 2007 1:20 PM > *To:* [email protected] > *Subject:* Re: [jibx-users] Null Collection Fields > > How to set a property reference to an empty collection instead of null > during unmarshalling when the associated element is missing from the > input xml. > > This binding causes the property to be null when the corresponding > element (list) is missing from the xml: > > <binding> > > <mapping name=”A” class=”a”> > > <collection > > name=”list” > > get-method=”getList” > > set-method=”setList” > > factory=”package.Factory.listFactory” <!—this method creates and > returns an ArrayList à > > item-type=”item” > > usage=”optional” > > test-method=”testListIsNullOrEmpty” /> > > </mapping> > > <mapping ---- for item --/> > > </binding> > > I changed the above to the following, it did not help. > > <binding> > > <mapping name=”A” class=”a”> > > <structure > > name="list" > > usage="optional" > > test-method=" testListIsNullOrEmpty"> > > <collection > > get-method=”getList” > > set-method=”setList” > > factory=”package.Factory.listFactory” <!—this method creates and > returns an ArrayList à > > item-type=”item” > > </structure> > > </mapping> > > <mapping ---- for item --/> > > </binding> > > What is the binding missing? Would using post-set method for this > purpose cause any issues/unwanted side effects? > > Thanks. > > Regards, > > Sunil > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
