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.

Reply via email to