1 2 Previous Next 17 Replies Latest reply on Mar 5, 2008 8:00 AM by aloubyansky Go to original post
      • 15. Re: How to force strict validation?
        rob.stryker

        Hey Alexey:

        I'm looking at the absolute latest JBoss XB (now, at least), specifically MarshallerImpl vs XercesXSMarshaller.

        It is plain to see (IMO) that MarshallerImpl does *not* throw any exceptions if a required attribute is missing. I just ran a test to verify.

        I did manage to get one marshaller to throw such an exception (after slight modification). I took the XercesXSMarshaller's and added the following code starting at 695:

         } // end if attrValue != null
         else if( currentAttribute.getRequired()){
         // its required and is not present. Must throw exception
         String name = currentAttribute.getAttrDeclaration().getName();
         throw new JBossXBRuntimeException("Required Attribute " + name + " is not present");
         }
        


        Once I made this modification to XercesXSMarshaller, my test passed successfully. After reading your suggestion about MarshallerImpl, I switched to that marshaller, and the exact same test failed to throw any sort of JBossXBRuntimeExcepton of any sort for missing a required attribute.

        The test, plainly, is that my schema REQUIRES an attribute (such as "name") and I am trying to marshall an object lacking this attribute.

        Since I've found a workaround in my edits to XercesXSMarshaller, I can move forward with my project; but I think some similar functionality needs to be added to MarshallerImpl if you intend for it to replace XercesXSMarshaller.

        Hope all's well! Thanks for your help!

        - Rob Stryker

        • 16. Re: How to force strict validation?
          rob.stryker

          Also, I suggest putting @deprecated tags in recently deprecated classes ;)

          • 17. Re: How to force strict validation?
            aloubyansky

            Required=true was used only to check that there is a Java property for the xml attribute in the Java class.

            I've created and fixed the jira issue for this.
            http://jira.jboss.com/jira/browse/JBXB-124

            1 2 Previous Next