permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Problem in unmarshalling an empty list using Castor. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem in unmarshalling an empty list using Castor." Watch "Problem in unmarshalling an empty list using Castor." New topic
Author

Problem in unmarshalling an empty list using Castor.

Kaushik Prakash
Greenhorn

Joined: Mar 23, 2009
Posts: 2
Hi,
I am facing a problem while unmarshalling into a Java bean from an xml. I am using Castor unmarshaller to populate the xml values into a Java bean. The problem is as follows:

In an xsd I have a simple type defined as follows:
<xs:simpleType name="ListTest">
<xs:list itemType="xs:string"/>
</xs:simpleType>

In the same xsd I have specified an element List as follows:

<xs:element name="List " type="ListTest" minOccurs="0" maxOccurs="1" nillable="true"> </xs:element>.

I use this xsd to validate my sample xml which has a field by name List
<List>abc def ghi</List>.

When I am unmarshalling the xml I am able to populate these values into a string array successfully.

But when the same element doesn't have any element, ie <List></List>, while unmarshalling I get a Null Pointer Exception. My inference is that in case of elements which are of type list, Castor expects elements to be present so that it can assign them into a string array object. In some cases there will be a valid scenario where elements will not be present. Could anyone help me out with this problem. Is there any other declaration I need to make in my xsd, so that while unmarshalling, an empty array object is obtained?

Regards,
Kaushik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in unmarshalling an empty list using Castor.