Keith,

just looking at http://castor.codehaus.org/xml-mapping.html, I cannot see the 
'container' attribute being documented anywhere. Or am I looking at the wrong 
place ? 

Werner

-----Ursprüngliche Nachricht-----
Von: Keith Visco [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 01. September 2005 07:18
An: [email protected]
Betreff: Re: [castor-user] Mapping collections when marshalling


Frank,

You need to use container="false" on your field mapping for the 
collection, as such:

  <field name="users"
         type="User"
         collection="collection"
         container="false">
  </field>

Hope that helps,

--Keith

Ratzlow, Frank (Extern) wrote:
> Hi folks,
> 
> I have a class structure similar to the following:
> 
> ====================================
> class AddressBook {
>         /** Collection*<User> */
>        * Collection* users;
> 
>         public void setUsers(*Collection* users) {
>                 this.users = users;
>         }
> 
>         public* Collection* getUsers() {
>                 return this.users;
>         }
> 
> }
> 
> 
> class User {
>         String firstname;
>         String lastname;
> 
>         public void setFirstname(String firstname) {
>                 this.firstname = firstname;
>         }
> 
>         public void setLastname(String lastname) {
>                 this.lastname = lastname;
>         }
> 
>         public String getFirstname() {
>                 return this.firstname;
>         }
> 
>         public String getLastname() {
>                 return this.lastname;
>         }
> 
> }
> 
> 
> ====================================
> 
> and a* castor* mapping file:
> ====================================
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/*Castor* Object Mapping DTD Version
> 1.0//EN"
>                          "_http://__*castor*.exolab.org/mappi ng.dtd_ 
> <http://www.google.com/url?sa=D%26q=http://castor.exolab.org/mapping.dtd>">
> 
> <mapping>
>         <class name="AddressBook">
>                 <map-to xml="addressbook"/>
>                 <field name="users"
>                         type="User"
>                        * collection*="*collection*">
>                 </field>
>         </class>
> 
>         <class name="User">
>                 <map-to xml="user"/>
>                 <field name="firstname"
>                         type="string">
>                         <bind-xml name="firstname"/>
>                 </field>
>                 <field name="lastname"
>                          type="string">
>                         <bind-xml name="lastname"/>
>                 </field>
>         </class>
> </mapping>
> ====================================
> 
> When i unmarshall from such a xml fragment:
> 
> ====================================
> <addressbook>
>         <users>
>                 <user>
>                         <firstname>Peter<firstname>
>                         <firstname>Miller<firstname>
>                 <user>
>                 <user>
>                         <firstname>Mary<firstname>
>                         <firstname>Lu<firstname>
>                 <user>
>                 <user>
>                         <firstname>Jonny<firstname>
>                         <firstname>Hot<firstname>
>                 <user>
>         </users>
> <addressbook>
> ====================================
> 
> the resulting object graph is absolutely as expected, means my user
> *collection* contains a bunch of users.
> But when I marshall it back to XML than I receive:
> ====================================
> <?xml version="1.0" encoding="UTF-8"?>
> <addressbook
>         xmlns:xsi="_http://www.w3.org/2001/XMLSche ma-instance_ 
> <http://www.google.com/url?sa=D%26q=http://www.w3.org/2001/XMLSchema-instance>"
>         xsi:type="java:AddressBook">
>         <users xsi:type="java:User">
>                 <firstname>Peter<firstname>
>                 <firstname>Miller<firstname>
>         </users>
>         <users xsi:type="java:User">
>                 <firstname>Mary<firstname>
>                 <firstname>Lu<firstname>
>         </users>
>   <users xsi:type="java:User">
>                 <firstname>Jonny<firstname>
>                 <firstname>Hot<firstname>
>         </user>
> <addressbook>
> ====================================
> 
> Is there a way to tell the mapping to put objects from collections in
> subelements of an enclosing XML-*collection* element?
> Just would like to see the output matching the input, with no "xsi"
> etc. and appropriate mapping of collections.
> 
> I saw the a simila thread 
> _http://www.mail-archive.com/[email protected]/msg00832.html_ but 
> it doesn't state how to achieve the enclosing collection root element 
> within a deep class structure - i think. Neither I can figure out from 
> this advice how to handle many different collections at different levels 
> in a object graph.
> 
> Any idea
> 
> TIA
> 
> Frank
> 
> P.S. JDK 1.4.1_05,* Castor* 0.9.6
> 
> "Coding ain't done till all tests run!"
> 


-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to