-
15. Re: Regression moving to JBossXB 2.0.2.Beta5
aloubyansky Mar 18, 2010 3:44 AM (in response to asoldano)Interesting, @XmlRootElement doesn't have "nillable" element as @XmlElement, although it can be nillable in XSD. -
16. Re: Regression moving to JBossXB 2.0.2.Beta5
aloubyansky Mar 18, 2010 4:05 AM (in response to aloubyansky)Strangely, the following test passes
public class XsiNilUnitTestCase extends AbstractJBossXBTest
{
private static String XSD =
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
" xmlns='http://www.w3.org/2001/XMLSchema'" +
" xmlns:jbxb='" + Constants.NS_JBXB + "'>" +
"<xsd:element name='root' nillable='true'>" +
" <xsd:complexType>" +
" <annotation>" +
" <appinfo>" +
" <jbxb:class impl='" + Root.class.getName() + "'/>" +
" </appinfo>" +
" </annotation>" +
" </xsd:complexType>" +
"</xsd:element>" +
"</xsd:schema>";
private static String XML_NIL_1 = "<root xsi:nil='1' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>";
private static String XML_NIL_0 = "<root xsi:nil='0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>";
private static String XML = "<root/>";
public XsiNilUnitTestCase(String name)
{
super(name);
}public void testUnmarshalling() throws Exception
{
SchemaBinding schema = XsdBinder.bind(new StringReader(XSD), null);
ElementBinding rootBinding = schema.getElement(new QName("root"));
assertNotNull(rootBinding);
assertTrue(rootBinding.isNillable());
Root root = (Root) UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(new StringReader(XML), schema);
assertNotNull(root);
root = (Root) UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(new StringReader(XML_NIL_1), schema);
assertNull(root);
root = (Root) UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(new StringReader(XML_NIL_0), schema);
assertNotNull(root);
}
public static class Root
{
}
} -
17. Re: Regression moving to JBossXB 2.0.2.Beta5
aloubyansky Mar 18, 2010 4:24 AM (in response to aloubyansky)The problem is the root element in your testcase is not nillable. If I change the element declaration above to
<xsd:element name='root' nillable='false'>
the nil attribute will be ignored during unmarshalling.
The root element creation happens in http://anonsvn.jboss.org/repos/jbossws/stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/binding/jbossxb/SchemaBindingBuilder.java
method bindParameterToElement(SchemaBinding schemaBinding, QName xmlName, QName xmlType)
The line is schemaBinding.addElement(xmlName, typeBinding);
This will create and return newly created root element. But it's not made nillable by default. Which kind of makes sense as the default, since by default nillable in XSD and binding annotations is false.
Can you consider adding a line there to make it nillable? E.g.
ElementBinding e = schemaBinding.addElement(xmlName, typeBinding);
e.setNillable(true);
-
18. Re: Regression moving to JBossXB 2.0.2.Beta5
asoldano Mar 18, 2010 5:15 AM (in response to aloubyansky)Thanks, adding that the test is passing. Currently running the full testsuite to see if everything is OK.
-
19. Re: Regression moving to JBossXB 2.0.2.Beta5
asoldano Mar 18, 2010 6:35 AM (in response to asoldano)Confirmed, it works. Thank you