Hi Keith et al,
 
I am working back through some old issues.
 
With 0.9.5 and org.exolab.castor.builder.javaclassmapping=type and the following schema:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType name="a">
        <sequence>
            <element name="stringField" type="string"/>
            <element name="intField" type="int"/>
    </complexType>
</schema>
 
and the following input:
<a>
    <stringField>aString</stringField>
    <intField>X</intField>
</a>
 
Unmarshaller.unmarshal() reasonably throws a MarshallingException.  However, the message string of this exception if the invalid value "X" without any other explanatory text.
 
I believe this is caused by UnmarshalHandler.toPrimitiveObject() throwing a NumberFormatException which is trapped by SAX.
 
In the interest of a more explanatory exception message string, I'd suggest trapping the NumberFormatException in UnmarshalHandler.endElement() - perhaps something like:
 
try {
    state.object = toPrimitiveObject(type,str);
}
catch(java.lang.NumberFormatException nfe) {
    String err = "unable to add text content to ";
    err += descriptor.getXMLName();
    err += " due to the following error: " + nfe;
    throw new SAXException(err);
}
 
 
Regards
Dean
 

Reply via email to