aspose file tools*
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 Java 8 in Action this week in the Java 8 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

Problem in unmarshalling an empty list using Castor.

Kaushik Prakash

Joined: Mar 23, 2009
Posts: 2
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"/>

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?

I agree. Here's the link:
subject: Problem in unmarshalling an empty list using Castor.
Similar Threads
using JAXB to convert Java Object to XML
XSD element validation
problem defining "this or that OR this and that" with Castor
null values in castor unmarshalling
schema: decimal type that allows empty string