Thanks Dennis, In this case I don't want the null elements to appear. I have compacted the array before marshalling and it works fine. This isn't a problem because JiBX is not being used for unmarshalling.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dennis Sosnoski Sent: 04 April 2008 04:37 To: JiBX users Subject: Re: [jibx-users] Marshalling array with null elements Hi Ian, Do you want the null items to be represented in the XML? If so, you can use nillable="true" to support this. If you *don't* want the null items represented in the XML you need to compact the array ahead of time (or hide it behind an iterator or such - but then you won't get an array when unmarshalling). - 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 Ian Cotton (icotton) wrote: > > Hi, > > I am trying to use JiBX to marshal an object containing an array. Some > elements of the array are null. This results in null pointer > exceptions in the marshalling code. > > My original mapping looked like this: > > <!-- Mapping for com.cisco.nm.acs.im.common.EnumDefinition --> > <mapping name="EnumDefinition" > class="com.cisco.nm.acs.im.common.EnumDefinition" > extends="com.cisco.nm.acs.im.common.PredefinedValueDefinition"> > <structure map-as="com.cisco.nm.acs.im.common.PredefinedValueDefinition"/> > <structure name="enumValues" usage="optional"> > <collection field="enumValues" usage="optional"/> > </structure> > </mapping> > > I realised that although the collection itself was marked as optional > the elements of it weren't. Since the elements of the array were a > single type, I modified the mapping as follows: > > <!-- Mapping for com.cisco.nm.acs.im.common.EnumDefinition --> > <mapping name="EnumDefinition" > class="com.cisco.nm.acs.im.common.EnumDefinition" > extends="com.cisco.nm.acs.im.common.PredefinedValueDefinition"> > <structure map-as="com.cisco.nm.acs.im.common.PredefinedValueDefinition"/> > <structure name="enumValues" usage="optional"> > <collection field="enumValues" usage="optional"> > <structure type="com.cisco.nm.acs.im.common.EnumValue" usage="optional"/> > </collection> > </structure> > </mapping> > > However, I am still getting null pointer exceptions, so this approach > didn't work. Is it possible in JiBX to marshal an array with null > elements or do I need to remove those elements prior to marshalling? > > Thanks, > > Ian Cotton. > > **Ian Cotton** > **Software Engineer** > **Product Development*** > * > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > Phone :**+44-20-8824-9219** > Mobile :**+44-7730-304406** > > > > > > United Kingdom > www.cisco.com/global/UK/ <http://www.cisco.com/global/UK/> > > > > This e-mail may contain confidential and privileged material for the > sole use of the intended recipient. Any review, use, distribution or > disclosure by others is strictly prohibited. If you are not the > intended recipient (or authorized to receive for the recipient), > please contact the sender by reply e-mail and delete all copies of > this message. > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------ - > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------ - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketp lace _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users