users@jaxb.java.net

Re: Issue with Nillable Elements....

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Sun, 29 Jan 2006 12:23:51 -0800

The problem is that when JAXB binds it to a list, it doesn't remember
your constraint that float, int, strings are supposed to occur in a
certain order.

So try

         List<Serializable> theList = x.getVarFloatAndVarIntAndVarString();
         theList.add(null);
         theList.add(2);
         theList.add("x1");

instead of:

         List<Serializable> theList = x.getVarFloatAndVarIntAndVarString();
         theList.add(2);
         theList.add("x1");

JAXB does know that only nillable element is VarFloat (as can be seen in
the annotation), so when it sees null in a list, it produces <varFloat>.

Sakala, Adinarayana wrote:
> Hi,
>
> I am using JAXB implementation that ships with JAX-WS2.0 EA3.
> Here is the schema that i am working with,
>
> <complexType name="OccuringStruct1">
> <sequence minOccurs="0" maxOccurs="unbounded">
> <element name="varFloat" type="xsd:float" nillable="true"/>
> <element name="varInt" type="xsd:int" minOccurs="1" maxOccurs="10"/>
> <element name="varString" type="xsd:string"/>
> </sequence>
> </complexType>
>
> The JAXB generated code is attached (OccuringStruct1.java).
>
> Client code:
> public void testOccuringStruct1() throws Exception {
> OccuringStruct1 x = new OccuringStruct1();
> List<Serializable> theList = x.getVarFloatAndVarIntAndVarString();
> theList.add(2);
> theList.add("x1");
>
> OccuringStruct1 yOriginal = new OccuringStruct1();
> theList = yOriginal.getVarFloatAndVarIntAndVarString();
> theList.add(22);
> theList.add("y");
>
> Holder<OccuringStruct1> y = new Holder<OccuringStruct1>(yOriginal);
> Holder<OccuringStruct1> z = new Holder<OccuringStruct1>();
>
> OccuringStruct1 ret = docClient.testOccuringStruct1(x, y, z);
>
> System.out.println(++i + "/" + test_count + ":testOccuringStruct1 complete");
> }
>
> The generated XML Message by JAXB Runtime is,
> <ns4:testOccuringStruct1 xmlns:ns4=http://objectweb.org/type_test/doc
> xmlns:ns5="http://objectweb.org/type_test/types">
> <ns4:x>
> <ns5:varInt>2</ns5:varInt>
> <ns5:varString>x1</ns5:varString>
> </ns4:x>
> <ns4:y>
> <ns5:varInt>22</ns5:varInt>
> <ns5:varString>y</ns5:varString>
> </ns4:y>
> </ns4:testOccuringStruct1>
>
> The above message looks wrong to me because the nillable element varFloat was ignored in the serialization of XML.
> I would have expected the xml message to look like,
> <ns4:testOccuringStruct1 xmlns:ns4=http://objectweb.org/type_test/doc
> xmlns:ns5="http://objectweb.org/type_test/types"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <ns4:x>
> <ns5:varFloat xsi:nil="true"/>
> <ns5:varInt>2</ns5:varInt>
> <ns5:varString>x1</ns5:varString>
> </ns4:x>
> <ns4:y>
> <ns5:varFloat xsi:nil="true"/>
> <ns5:varInt>22</ns5:varInt>
> <ns5:varString>y</ns5:varString>
> </ns4:y>
> </ns4:testOccuringStruct1>
>
> Is this a known issue with JAXB2.0 EA3 or am i doing something wrong?
>
> Any help is really appreciated.
>
> thanks,
> Adi Sakala
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com