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);
bWriter.getBindingConfiguration().setMapIDs(false);
bWriter.enablePrettyPrint();
Test test = new Test();
TestObject test1 = new TestObject();
TestObject test2 = new TestObject();
test1.setName("name1");
test2.setName("name2");
TestObject[] testObjects = new TestObject[]{test1, test2};
test.setArray1(testObjects);
test.setArray2(testObjects);
bWriter.write("test", test);
bWriter.flush();
and I get the following xml as expected.
<test>
<array1>
<TestObject>
<name>name1</name>
</TestObject>
<TestObject>
<name>name2</name>
</TestObject>
</array1>
<array2>
<TestObject>
<name>name1</name>
</TestObject>
<TestObject>
<name>name2</name>
</TestObject>
</array2>
</test>
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.
Thanks
Tom
--
View this message in context:
http://www.nabble.com/-betwixt--Problem-deserializing-to-object-with-multiple-array-properties-tf4241867.html#a12070112
Sent from the Commons - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]