when you created your class did you generate it from an xsd such that all of the add, remove methods are in place for the Marshaled to use when marshalling the class. If you created the class by hand I don't know that the marshaled has any idea how to marshal object members of a parent class. Being fairly new to Castor I could be wrong about that but I believe the marshaller iterates over the members of a class using the xxxDescriptor classes that get generated from the xsd for your class.
 
Bryan LaPlante
-----Original Message-----
From: Rochana Attale [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 08, 2004 2:38 PM
To: [EMAIL PROTECTED]
Subject: [castor-user] Why aren't objects such as Vectors, ArrayLists not Marshalled?

Hi,
 
Here is my code:
 
========================================
import java.io.Serializable;
import java.util.*;
 
public class TestObj implements Serializable {

  private Vector list;
 
  public TestObj(Vector v) {
    list = v;
  }
}

========================================

import java.io.*;
import java.util.*;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.*;

public class test {
  public static void main(String args[]) {
    // Create a new TestObj
    Vector v = new Vector();
    v.add("Element 1");
    v.add("Element 2");
    TestObj test = new TestObj(v);
    // Create a File to marshal to
    try {
      FileWriter writer = new FileWriter(new File("D:\\test.xml"));

      Marshaller.marshal(test, writer);
    }
    catch (MarshalException ex) {
      ex.printStackTrace();
    }
    catch (ValidationException ex) {
      ex.printStackTrace();
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }

  }

}

My problem is that "test.xml" ends up looking like this without the Vector:

<?xml version="1.0" encoding="UTF-8"?>

<test-obj/>

 
But if I marshalled the vector object by saying "Marshaller.marshal(v, writer);" the Vector is properly Marshalled.
 
What am I doing wrong?
 
Thanks in advance,
 
Rochana


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to