1 2 Previous Next 19 Replies Latest reply on Mar 18, 2010 6:35 AM by asoldano Go to original post
      • 15. Re: Regression moving to JBossXB 2.0.2.Beta5
        aloubyansky
        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

          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

            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

              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
                Confirmed, it works. Thank you
                1 2 Previous Next