Hi All-
I am a newbie to castor and facing an issue where in my arraylist is empty
after unmarshal.
This is how my xml looks like,
1. Demo xml
<?xml version="1.0" encoding="UTF-8"?>
<Parent>
<Partner>
<person>
<firstname>Jason</firstname>
<lastname>Bong</lastname>
<gender>M</gender>
</person>
<address>
<line1>Addres 1</line1>
<city>City1</city>
<state>LA</state>
<zip>14323</zip>
</address>
</Partner>
<Partner>
<person>
<firstname>Bong</firstname>
<lastname>Jason</lastname>
<gender>M</gender>
</person>
<address>
<line1>1000 Drive</line1>
<line2>Address 2</line2>
<city>CIty2</city>
<state>LA</state>
<zip>12334</zip>
</address>
</Partner>
</Parent>
2. Mapping xml
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="com.demo.Parent">
<map-to xml="Parent" />
<field name="partners" type="com.demo.Partner"
collection="arraylist">
<bind-xml name="Partner" node="element"
location="Parent" />
</field>
</class>
<class name="com.demo.Address">
<map-to xml="address"/>
<field name="line2" type="java.lang.String">
<bind-xml name="line2" node="element" />
</field>
<field name="line1" type="java.lang.String">
<bind-xml name="line1" node="element" />
</field>
<field name="zip" type="java.lang.String">
<bind-xml name="zip" node="element" />
</field>
<field name="state" type="java.lang.String">
<bind-xml name="state" node="element" />
</field>
<field name="city" type="java.lang.String">
<bind-xml name="city" node="element" />
</field>
</class>
<class name="com.demo.Partner">
<map-to xml="Partner"/>
<field name="address" type="com.demo.Address">
<bind-xml name="address" node="element" />
</field>
<field name="person" type="com.demo.Person">
<bind-xml name="person" node="element" />
</field>
</class>
<class name="com.demo.Person">
<map-to xml="person"/>
<field name="gender" type="java.lang.String">
<bind-xml name="gender" node="element" />
</field>
<field name="lastname" type="java.lang.String">
<bind-xml name="lastname" node="element" />
</field>
<field name="firstname" type="java.lang.String">
<bind-xml name="firstname" node="element" />
</field>
</class>
</mapping>
Code snippet which I am using for unmarshal,
Unmarshaller um = xmlcontext.createUnmarshaller();
Parent parent=(Parent) um.unmarshal(new InputSource(new
FileReader("xml/Demo.xml")));
The exception which I am getting is, Class for root element 'parent' not
found.
If I use static method 'unmarshal' (Parent.class,"read xml from
stream"),the arraylist is empty.
Do I need to use descriptor classes here?
I guess I am missing something obvious.
Any help is appreciated.
Thanks,
Sam
--
View this message in context:
http://old.nabble.com/Collections-arraylist-empty-tp27532141p27532141.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email