commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomppa <>
Subject [betwixt] Problem deserializing to object with multiple array properties
Date Thu, 09 Aug 2007 10:35:00 GMT

Here's the scenario:

public class Test {

	private TestObject[] array1;
	private TestObject[] array2;

	public Test() {
		this.array1 = null;
		this.array2 = null;
	public TestObject[] getArray1() {
		return array1;
	public TestObject[] getArray2() {
		return array2;
	public void setArray1(TestObject[] array1) {
		this.array1 = array1;
	public void setArray2(TestObject[] array2) {
		this.array2 = array2;

where TestObject is just a simple POJO with a String property.

My code to serialize is as follows.

	fWriter = new FileWriter("output.xml");
	BeanWriter bWriter = new BeanWriter(fWriter);

	Test test = new Test();
	TestObject test1 = new TestObject();
	TestObject test2 = new TestObject();
	TestObject[] testObjects = new TestObject[]{test1, test2};
	bWriter.write("test", test);

and I get the following xml as expected.


When deserializing this with

	BeanReader bReader = new BeanReader();
	bReader.registerBeanClass("test", Test.class);
	Test read = (Test)bReader.parse(new File("output.xml"));

I get an EmptyStackException. 

If I only set array1 and round-trip I get a Test object with array1 set to
an empty TestObject array. I traced and found that only setArray1 is called
during deserialization. With only one array property in Test everything
works fine. 

How can I tell betwixt to use the right setter for the right array? I have
to use the arrays as properties because the code is generated.

View this message in context:
Sent from the Commons - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message