Java Mailing List Archive

Home » user.castor »

[castor-user] Unmarshalling a stream with no mappable element should return null or
throw an exception

Dumont Arnaud


Replies: Find Java Web Hosting

Author LoginPost Reply
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();
MyBean myBean = un.unmarshal(new StringReader(myString));

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

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

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

Arnaud Dumont

To unsubscribe from this list, please visit:

©2008 - Jax Systems, LLC, U.S.A.