Hi all,

I'm using a simple Unmarshaller to unmarshall a String into a Java
bean, using Castor v1.2:
Unmarshaller un = new Unmarshaller(MyObject.class);
Mapping mapping = new Mapping();
mapping.loadMapping(mappingFilePath);
un.setMapping(mapping);
MyBean myBean = un.unmarshal(new StringReader(myString));

My mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
 <class name="com.MyBean">
       <map-to xml="myBean" />
       <field name="myField" type="string" />
       [...]
 </class>
</mapping>

When myString contains XML data corresponding to MyBean, the
unmarshalling works correctly.
But when myString is an empty String or does not contain XML data
corresponding to MyBean, I would expect myBean to be null or an
exception to be thrown. Instead, I get a newly instantiated MyBean,
with no fields set.
Is there a way to detect that no XML data corresponding to the bean
class was found in myString (like a "required" attribute on the
<class> tag?)?
I couldn't find anything in the documentation or in the mail archive
about this. Am I missing something?

I could parse the String myself, looking for a <myBean> tag, but I
would prefer the tag name to stay configurable in the Castor mapping
file.

Thanks in advance and many thanks for your great Castor library.

Arnaud Dumont

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to