Mark,
Mark Chamness wrote:
Hi, Castor appears to require a root element to unmarshall objects. How would it handle a continuous stream of objects over a network?
By the way, is the website down? http://www.castor.org/
http://castor.codehaus.org should do the trick for the time being.
Werner
-mark
-----Original Message-----
From: Mark Chamness [mailto:[EMAIL PROTECTED] Sent: Thursday, May 12, 2005 9:11 AM
To: [email protected]
Subject: [castor-user] a sequence of objects can be serialized but not deserialized
While sequence of objects can be serialized to a stream, they can't be deserialized. The motivation for this comes from experience with java serialization: oos.writeInt(12345); oos.writeObject("Today"); oos.writeObject(new Date());
and then...
int i = ois.readInt(); String today = (String) ois.readObject(); Date date = (Date) ois.readObject();
The error message for the following test case is: Parsing Error : The markup in the document following the root element must be well-formed.
public void testMarshalMultipleObjects() throws Exception { TestObject testObject1 = new TestObject(); testObject1.testString = "test one"; TestObject testObject2 = new TestObject(); testObject2.testString = "test two"; StringWriter stringWriter = new StringWriter(); Marshaller marshaller = new Marshaller(stringWriter); marshaller.setSupressXMLDeclaration(true); //doesn't matter marshaller.marshal(testObject1); marshaller.marshal(testObject2); StringReader stringReader = new StringReader(stringWriter.toString()); Unmarshaller unmarshaller = new Unmarshaller(TestObject.class); TestObject newTestObject1 = (TestObject) unmarshaller.unmarshal(stringReader);//fails TestObject newTestObject2 = (TestObject) unmarshaller.unmarshal(stringReader); Assert.assertEquals(testObject1.testString, newTestObject1.testString); Assert.assertEquals(testObject2.testString, newTestObject2.testString); }
public class TestObject { public String testString;
public TestObject() { }
public String getTestString() { return testString; }
public void setTestString(String testString) { this.testString = testString; } }

