[ 
https://jira.codehaus.org/browse/JIBX-449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=278935#comment-278935
 ] 

Klaus Claszen commented on JIBX-449:
------------------------------------

As I figured out there is a change in the created binding.xml file between the 
two JIBX versions:

*JIBX 1.2.2*

{code}
<binding xmlns:tns="http://foo.bar"; name="binding" package="bar.foo"
        trim-whitespace="true">
        <namespace uri="http://foo.bar"; default="elements" prefix="tns" />
        <mapping abstract="true" type-name="tns:myCollection" 
class="bar.foo.MyCollection">
                <value style="element" name="name" get-method="getName" 
set-method="setName" />
                <value style="element" name="active" get-method="isActive" 
set-method="setActive" />
                <collection get-method="getItems" set-method="setItems"
                        create-type="java.util.ArrayList">
                        <value style="element" name="item" 
type="java.lang.Integer" />
                </collection>
        </mapping>
        <mapping class="bar.foo.MyCollection" name="myCollection">
                <structure map-as="tns:myCollection" />
        </mapping>
</binding>
{code}

*JIBX 1.2.3*

{code}
<binding xmlns:tns="http://foo.bar"; name="binding" package="bar.foo"
        trim-whitespace="true">
        <namespace uri="http://foo.bar"; default="elements" prefix="tns" />
        <mapping abstract="true" type-name="tns:myCollection" 
class="bar.foo.MyCollection">
                <value style="element" name="name" get-method="getName" 
set-method="setName" />
                <value style="element" name="active" get-method="isActive" 
set-method="setActive" />
                <collection get-method="getItemList" set-method="setItemList"
                        usage="optional" create-type="java.util.ArrayList">
                        <value style="element" name="item" 
type="java.lang.Integer" />
                </collection>
        </mapping>
        <mapping class="bar.foo.MyCollection" name="myCollection">
                <structure map-as="tns:myCollection" />
        </mapping>
</binding>
{code}

In the 1.2.3 version the _usage="optional"_ attribute is placed to the 
collection element. This seems to cause the different behaviour. To get the old 
behaviour back we are currently removing this attribute from the binding file. 
This works as a workaround but we would prefer to have the old build in 
behaviour back.

> change in collection behavior (null references) between JIBX version 1.2.3 
> and JIBX version 1.2.2
> -------------------------------------------------------------------------------------------------
>
>                 Key: JIBX-449
>                 URL: https://jira.codehaus.org/browse/JIBX-449
>             Project: JiBX
>          Issue Type: Bug
>          Components: BindGen, core
>    Affects Versions: JiBX 1.2.3
>            Reporter: Klaus Claszen
>         Attachments: jibx-collection-test.zip
>
>
> We noticed a really significant change in collection behavior between JIBX 
> version 1.2.3 and JIBX version 1.2.2.
> As documented in the collection element documentation 
> (http://jibx.sourceforge.net/binding/collection-element.html) unmarshalling 
> an optional collection behaves like this: "If an element name is used with an 
> optional collection, and that name is missing from an input XML document, the 
> collection property will be set to null." Thus (we expect and noticed in the 
> past) if no element name is used the collection property will not be set to 
> null (but will be an empty collection).
> With version 1.2.3 the collection property will be set to null, even if NO 
> element name in the binding.xml is used on the optional collection.
> To reproduce the changed behavior I provide a simple maven project using JIBX 
> 1.2.3 with the following schema:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
>                 xmlns:tns="http://foo.bar";
>                 elementFormDefault="qualified" 
>                 targetNamespace="http://foo.bar";>
>                 
>                 <xs:element name="myCollection" type="tns:myCollection"/>
>                 
>                 <xs:complexType name="myCollection">
>                                <xs:sequence>
>                                                <xs:element type="xs:string" 
> name="name" />
>                                                <xs:element type="xs:boolean" 
> name="active" />
>                                                <xs:element type="xs:int" 
> name="item" minOccurs="0" maxOccurs="unbounded" />
>                                </xs:sequence>
>                 </xs:complexType>
>                 
> </xs:schema>
> The maven project will generate the XML mapping sources (MyCollection.java) 
> and a binding.xml file. There is a simple test 
> bar.foo.JibxUnmarshallingTest.testUnmarshalXmlWithMissingListItems()
> which will unmarshal an XML with no items for a list member and the result is 
> that the object member list is null (test fails).
> If you change the jibx version in the pom.xml to 1.2.2 (and do some minor 
> code changes in the test classes because getter and setter method names of 
> generated code also changed from 1.2.2 (getItems()) to 1.2.3 (getItemList()) 
> the list member of the unmarshalled object will be an empty list (test 
> success)?.
> This issue breaks our code as we do not expect to get any null reference when 
> requesting a list of an unmarshalled object.
> (There is a Wish Issue JIBX-418 on this topic - but I think it is a 
> significant bug).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
jibx-devs mailing list
jibx-devs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-devs

Reply via email to