Java Mailing List Archive

Home » user.castor »

[castor-user] The class for the root element 'array-list'

Zachariah Young


Replies: Find Java Web Hosting

Author LoginPost Reply
I'm trying to work through a simple use case for Castor and I'm getting the following error.  What I'm trying to do is read in an XML file with a list of objects.

Exception in thread "main" org.exolab.castor.xml.MarshalException: The class for the root element 'array-list' could not be found.{File: [not available]; line: 2; column: 13}

My simple entity looks like the following.

public class Pet implements Serializable  {

    private String Name;
    private String Type;

    public void setName(String name) {
        Name = name;

    public String getName() {
        return Name;

    public void setType(String type) {
        this.Type = type;

    public String getType() {
        return Type;
My mapping file looks like this.

<class name="com.zandroid.model.Pet" auto-complete="true">        
   <map-to xml="pet"/>
   <field name="name" type="string">
      <bind-xml name="name" node="element"/>
   <field name="type" type="string">
      <bind-xml name="type" node="element"/>

In my main class I have the follow code.

    public static void main(String[] args) throws IOException, MappingException, MarshalException, ValidationException {

        List<Pet> arrayList = new ArrayList<Pet>();
        Pet pet = new Pet();
        Pet pet1 = new Pet();
        Writer fileWriter = new FileWriter("text.xml");       
        Mapping mapping = new Mapping();

        XMLContext context = new XMLContext();
        Marshaller marshaller = context.createMarshaller();

        FileReader reader = new FileReader("text.xml");

        ArrayList<Pet> pets = (ArrayList<Pet>)context.createUnmarshaller().unmarshal(reader);
        for (Pet pet2 : pets) {

This code creates the following xml file.

So when I go Unmarshaller the XML file I get the The class for the root element 'array-list'.

1.  Should I be doing something different in my mapping file?
2.  Should I create another class that has a property of List<Pet>?
3.  Is this the correct use case for Castor?

Note:  I'm also trying to get this to work in Spring 3.  Also I have review this article

Thanks for the help.
Zachariah Young

©2008 - Jax Systems, LLC, U.S.A.