Hello,
I am new to castor-xml and try to map a collection of Person objects to an
xml file. I understand that directly mapping a java.util.Collection
implementation (Vector, HashSet, ...) is not possible, right. So I created a
wrapper class PersonSet
public final class PersonSet{
private Collection m_persons = new Vector();
public PersonSet()
{
m_persons = new Vector();
}
public Collection getPersons()
{
return m_persons;
}
public void setPersons(Collection persons)
{
m_persons = persons;
}
}
and a mapping file
<mapping>
<class name="com.bergner.manplan.test.util.PersonSet">
<map-to xml="person-set"/>
<field name="persons" collection="vector"
type="com.bergner.manplan.model.person.Person">
<bind-xml name="person"/>
</field>
</class>
<class name="com.bergner.manplan.model.person.Person">
<map-to xml="person"/>
<field name="id" type="integer">
<bind-xml name="id" node="attribute"/>
</field>
<field name="givenName" type="string">
<bind-xml name="first-name" node="element"/>
</field>
...
</class>
<class name="com.bergner.manplan.model.person.Address">
<map-to xml="address"/>
<field name="id" type="integer">
<bind-xml name="id" node="attribute"/>
</field>
<field name="street" type="string">
<bind-xml name="street" node="element"/>
</field>
...
</class>
<class name="com.bergner.manplan.service.role.Role">
<map-to xml="role"/>
<field name="id" type="integer">
<bind-xml name="id" node="attribute"/>
</field>
<field name="name" type="string">
<bind-xml name="name" node="element"/>
</field>
...
</class>
</mapping>
What I get upon marshalling, however, looks like
<?xml version="1.0" encoding="UTF-8"?>
<person-set>
<persons id="1" xsi:type="java:com.bergner.manplan.model.person.Person"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<address id="1">
<email>[EMAIL PROTECTED]</email>
<phone-number>00700-87665</phone-number>
<fax-number>00700-76554</fax-number>
<postal-code>7867-5</postal-code>
<city>Tullamyre</city>
<street>Bourbon Street</street>
</address>
<password>AKQ628B/UZd919r3eJf+S10dxZ4=</password>
<given-name>Jonathan</given-name>
<surname>Masterson</surname>
<username>j.master</username>
</persons>
<persons id="2" xsi:type="java:com.bergner.manplan.model.person.Person"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<address id="2">
<email>[EMAIL PROTECTED]</email>
<phone-number>00700-76443</phone-number>
<fax-number>00700-999877</fax-number>
<postal-code>45332</postal-code>
<city>Bloody Mary</city>
<street>Wodka Rd.</street>
</address>
<password>IQOJh55CmeRMfqrS5kjxxYfi/DI=</password>
<given-name>Joseph</given-name>
<roles id="1" xsi:type="java:com.bergner.manplan.service.role.Role">
<name>administrator</name>
<description>Supersuer</description>
</roles>
<roles id="5" xsi:type="java:com.bergner.manplan.service.role.Role">
<name>landscape</name>
<description>Sculptor of rivers, mountains and
valleys</description>
</roles>
<roles id="4" xsi:type="java:com.bergner.manplan.service.role.Role">
<name>airconditioning</name>
<description>Amenable climates for free</description>
</roles>
<surname>Carlton</surname>
<username>j.carl</username>
</persons>
...
</person-set>
and Castor will complain about multiple "persons" entries when trying to
unmarshal that xml back to a PersonSet. What am I missing? Any help would be
greatly appreciated since even after extensively searching this mailing list
for similar problems I could not find a solution. I played around with the
mapping file, ommiting the map-to element for dependant objects, changing
persons to person in various places etc pp but to no avail. Oh, I am using
Castor 0.9.4.1.
Thanks,
Olaf
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev