Is there a method called "getRoles" in your ArrayList class? In your
mapping, you have a mapping for class ArrayList which specifies a field
called "roles". So Castor is looking the "getters/setters". If your
ArrayList class is actually a java.util.ArrayList...then just remove the
mapping, it's not needed.

Also, you have a getter method called "getRoles" that returns an
ArrayList and a setter called "setRoles" which takes a string... I'm
assuming this is an error...since you're assigning and returning the
same reference in the methods.

Also, you didn't define a mapping for the Role class (does one exisit?)

I think you need to align the mapping a bit better with the object model
and it'll work better for you.

--Keith


"Joshi, Nirmit (US - Washington D.C.)" wrote:

> Hi! As a new user, I am struggling a bit here. I hope this is a
> trivial problem and I get many responses J
>
> I need to do marshalling/unmarshalling for a simple object that
> contains a collection. Some help with defining the mapping file will
> be much appreciated. I am getting an exception: �Exception in thread
> "main" org.exolab.castor.mapping.MappingException: The method getRoles
> in class ArrayList accepting/returning object of type null was not
> found�
>
> The Java Class:
>
> import java.util.*;
>
> public class UserProfile
>
> {
>
>             private String userId;
>
>             private String userName;
>
>             private ArrayList roles;
>
>             public UserProfile() {
>
>             }
>
>             public ArrayList getRoles()
>
>             {
>
>                         return roles;
>
>             }
>
>             public void setRoles(String role)
>
>             {
>
>                         this.roles = roles;
>
>             }
>
> // getters and setters for other fields
>
> }
>
> The mapping file I have defined is:
>
> <!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version
> 1.0//EN"  "http://castor.exolab.org/mapping.dtd";>
>
> <mapping>
>
>   <description>Basic mapping example</description>
>
>   <class name="UserProfile" auto-complete="true">
>
>     <map-to xml="user_data"/>
>
>     <field name="userId">
>
>             <bind-xml name="user_id" node="element"/>
>
>     </field>
>
>     <field name="userName">
>
>             <bind-xml name="user_name" node="element"/>
>
>     </field>
>
>     <field name="roles" collection="collection" type="ArrayList">
>
>             <bind-xml name="user_roles"/>
>
>     </field>
>
>   </class>
>
>   <class name="ArrayList" auto-complete="true">
>
>     <field name="roles">
>
>             <bind-xml name="role" node="element"/>
>
>     </field>
>
>   </class>
>
> </mapping>
>
> I�d like to see an output XML in the following format:
>
> <?xml version="1.0" encoding="UTF-8" ?>
>
> <user_data>
>
>           <user_id>N1001</user_id>
>
>           <user_name>Nirmit</user_name>
>
>           <user_roles>
>
>                    <role>friend</role>
>
>                    <role>philosopher</role>
>
>                    <role>guide</role>
>
>           </user_roles>
>
> </user_data>
>
> Any recommendations?
>
> Thanks,
> Nirmit
> This message (including any attachments) contains confidential
> information intended for a specific individual and purpose, and is
> protected by law. If you are not the intended recipient, you should
> delete this message. Any disclosure, copying, or distribution of this
> message, or the taking of any action based on it, is strictly
> prohibited.

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to