You should be able to simplify your definition to just:

<collection name="info" style="element" field="lines" item-type="com.voila.LineType" usage="optional"/>

rather than using the wrapping structure. This will skip the <info> element completely when marshalling if the lines field is null. If you want to check for an empty collection (non-null, but with no items in the collection) you'd need to use a test-method to see if the collection is empty.

 - Dennis

[EMAIL PROTECTED] wrote:

Hello,

I have the following mapping:-

<mapping>
        <mapping name="member" class="com.voila.Member" >
            <value style="attribute" name="name" field="name"
usage="required"/>
   <structure name="info" usage="optional">
     <collection style="element" field="lines"
item-type="com.voila.LineType" usage="optional"/>
   </structure>
</mapping>

Note that the lines are contained in an **ArrayList**

The unmarshalling of the following 2 messages is OK:-

     <member>
        <name>cedric</name>
       <info>
                <line>first line</line>
                <line>second line</line>
                <line>third line</line>
                <line>fourth line</line>
        </info>
     </member>

     <member>
        <name>cedric</name>
     </member>



HOWEVER,when I mashall a class that contains only the element 'name', I
would expect :-

     <member>
        <name>cedric</name>
     <member>


But JiBX returns me the following:-

     <member>
        <name>cedric</name>
       <info></info>
     </member>

Do you see the problem? The structure info contains an empty ArrayList
'lines', but the optional structure 'info' is rendered anyway ...

Is there a way to prevent this in the mapping file?
If not, don't you think it should be handled by JiBX as a feature (if a
structure is empty, don't even bother rendering its delimiter tags)?
If there is no way to acheave this "off the box" maybe someone has
experienced the same problem and has some code (e.g. overload/modified
JiBX code) that I could reuse?

Merci!

Cedric


------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users





-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to