Hello all,
I use castor-0.9.4.3 SourceGenerator.
When I try to marshal objects with validation=true
(myMarshaller.setValidation(true);), I get NullPointerException.
This is a stack trace:
java.lang.NullPointerException
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:741)
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:753)
at
org.exolab.castor.xml.Validator.validate(Validator.java:122)
at
org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:250)
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:885)
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:753)
at
org.exolab.castor.xml.Validator.validate(Validator.java:122)
at
org.exolab.castor.xml.Marshaller.validate(Marshaller.java:1770)
at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:717)
at
myClass.doMarshal(MyClass.java:201)
Exactly the same exception is thrown when I try to unmarshal the xml to
objects.
When I turn off the validation (setting validation to false), the proper
xml is generated. I validated it in XMLSpy and all is correct, the xml
is an instance of XMLSchema which was used by Castor SourceGenerator.
I gave a look at castor source code (XMLClassDescriptorImpl) and here
are the lines:
/**
* Validates the given object
* @param object the Object to validate
* @param context the ValidationContext
*/
public void validate(Object object, ValidationContext context)
throws ValidationException
{
if (object == null) {
throw new ValidationException("Cannot validate a null
object.");
}
// **** line 741 is below
if (!getJavaClass().isAssignableFrom(object.getClass())) {
String err = "The given object is not an instance of the
class"+
" described by this ClassDecriptor.";
throw new ValidationException(err);
}
XMLFieldDescriptor[] localElements = getElementArray();
if (_extends != null) {
//-- cascade call for validation
if (_extends instanceof XMLClassDescriptorImpl) {
// *** line 753 is below
((XMLClassDescriptorImpl)_extends).validate(object,
context);
}
else {
TypeValidator validator = _extends.getValidator();
if (validator != null)
validator.validate(object, context);
}
//....
And here is getJavaClass() function
/**
* Returns the Java class represented by this descriptor.
*
* @return The Java class
*/
public Class getJavaClass() {
return _class;
} //-- getJavaClass
Has anyone an idea what may be wrong? Is there a possibility that
generated classes are not correct?
Thanks in advance,
Grzegorz Misztalewski
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev