gunther hi,
please find the comments in jibx site regarding nullable attribute
The marshalling behavior when the attribute is "true" and the
object reference is null depends on whether the binding defines
the corresponding element as optional or required. If the element
is optional it will simply be left out of the marshalled document.
If the element is required it will be written with an
xsi:nil="true" attribute. This attribute can only be used with
objects that are bound to an element name.
Regards,
venakt annangi
On 7/25/07, Günther Wieser <[EMAIL PROTECTED]> wrote:
hi,
i found some confusing information regarding the usage of xsi:nil
to indicate if an obejct or value is null.
on the mailing list i found the following entry:
[jibx-users] JiBX 1.1 beta4 release
Dennis Sosnoski
Thu, 25 May 2006 21:26:05 -0700
4. Added nillable attribute to object group and value element,
supporting the xsi:nil attribute at runtime (requires element
name, not allowed on abstract mapping)
in the docs i found out that the value element doesn't support
nillable=true. interestingly i can add that to my binding and it
compiles well. but when it comes to runtime, i get a weird exception:
java.lang.IndexOutOfBoundsException: only START_TAG can have
attributes END_TAG seen ...</street>\r\n\t\t<city xsi:nil="true" /
>... @10:26
at org.xmlpull.mxp1.MXParser.getAttributeValue(MXParser.java:927)
at org.jibx.runtime.impl.XMLPullReaderFactory
$XMLPullReader.getAttributeValue(XMLPullReaderFactory.java:395)
at org.jibx.runtime.impl.UnmarshallingContext.getAttributeValue
(UnmarshallingContext.java:356)
at org.jibx.runtime.impl.UnmarshallingContext.attributeBoolean
(UnmarshallingContext.java:1881)
at
data.Address.JiBX_C__JavaDev322_JiXB_Test_src_customer_binding_unmars
hal_1_1(Address.java)
at
data.Customer.JiBX_C__JavaDev322_JiXB_Test_src_customer_binding_unmar
shal_1_2(Customer.java)
at
data.JiBX_C__JavaDev322_JiXB_Test_src_customer_bindingCustomer_access
1.unmarshal()
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement
(UnmarshallingContext.java:2537)
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument
(UnmarshallingContext.java:2680)
at test.CustomerWAddressTest.main(CustomerWAddressTest.java:23)
i don't get this is i remove 'nillable=true' from the binding, but
then of course the value is not null, it's an empty string (which
means something different in our case).
here's the binding:
<?xml version="1.0" encoding="ISO-8859-2"?>
<binding>
<mapping name="customer" class="data.Customer" flexible="true"
ordered="false" allow-repeats="true">
<value name="id" set-method="setJiXBId" get-method="getJiXBId"/>
<value name="first" set-method="setJiXBFirstName" get-
method="getJiXBFirstName"/>
<value name="last" set-method="setJiXBLastName" get-
method="getJiXBLastName"/>
<!-- <collection field="addresses" flexible="true"
ordered="false"> -->
<structure name="address" type="data.Address" allow-repeats="true"
flexible="true" ordered="false" set-method="addAddress" get-
method="getAddress">
<value name="id" set-method="setJiXBId" get-method="getJiXBId"/>
<value name="street" set-method="setJiXBStreet" get-
method="getJiXBStreet" usage="optional"/>
<value name="city" set-method="setJiXBCity" get-
method="getJiXBCity" usage="optional" nillable="true"/>
</structure>
<!-- </collection> -->
</mapping>
</binding>
and here's the example data:
<?xml version="1.0" encoding="ISO-8859-2"?>
<customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance ">
<id>1234</id>
<first>Heinz</first>
<last>Prueller</last>
<asdasd>asasd</asdasd>
<address>
<id>111</id>
<street>Daham 1</street>
<city xsi:nil="true" />
</address>
</customer>
so do i need to change something in my binding? could i use
structure instead of value (and if how can i do that)?
br,
günther
--
Günther Wieser
---------------------------------------------------------------------
----
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a
browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users
---------------------------------------------------------------------
----
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a
browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users