Hi Sam,
On 11.02.2010 01:00, Sam-1234 wrote:
Thanks for reply Werner !
Actually I did couple of changes to make it work.
One change I did is I am creating an instance (new) of Unmarshaller
now,earlier I was using XMLContext for that.
As I understand from documentation, if mappings are being used then
Marshal/unmarshal should be created using XMLContext.
Yes, correct. If you are using the static methods of Unmarshaller, any
mapping will be ignored.
Is there any issue I
will be facing due to creation Unmarshaller instance going forward?
Not, not at all.
Regards
Werner
Please advice.
Thanks,
Sam
Werner Guttmann-6 wrote:
Hi Sam,
can you please change the class mapping for the Parent class as follows:
OLD:
<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>
NEW:
<class name="com.demo.Parent">
<map-to xml="Parent" />
<field name="partners" type="com.demo.Partner"
collection="arraylist">
<bind-xml name="Partner" node="element" />
</field>
</class>
I simply removed the location attribute from the above<bind-xml/>. That
should remove your problem (as far as I can tell).
Cheers
Werner
On 10.02.2010 15:36, Sam-1234 wrote:
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
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email