Write once? Java Serialization?
Hi,
I have a simple java serialization issue on solaris. The same piece of code runs on windows and linux, but Solaris throws an exception on me. Any idea?
WinXP SP2, jdk1.4.2_11
RH Linux 7.3, jdk1.4.2_11
Solaris9 jdk1.4.2_13
Here is my code:
Tester.java
import java.io.*;
public class Tester
{
String marshellChild(Child child) throws Exception
{
Parent parent = child.getParent();
ByteArrayOutputStream fo = new ByteArrayOutputStream();
ObjectOutputStream so = new ObjectOutputStream(fo);
so.writeObject(parent);
so.flush();
so.close();
return new String(fo.toByteArray());
}
Child unmarshellChild(String strep) throws Exception
{
byte[] bytes = new String(strep).getBytes();
InputStream io = new ByteArrayInputStream(bytes);
ObjectInputStream os = new ObjectInputStream(io);
Parent parent = (Parent) os.readObject();
return parent.getChild();
}
public static void main(String[] args) throws Exception
{
Parent parent = new Parent();
Child child = new Child();
parent.setChild(child);
child.setParent(parent);
Tester tester = new Tester();
String strep = tester.marshellChild(child);
System.out.println(strep);
Child newChild = tester.unmarshellChild(strep);
System.out.println(newChild);
}
}
Parent.java
import java.io.*;
public class Parent implements Serializable
{
private Child child;
public void setChild(Child child)
{
this.child = child;
}
public Child getChild()
{
return this.child;
}
public String getName()
{
return "PARENT";
}
}
Child.java
import java.io.*;
public class Child implements Serializable
{
private Parent parent;
public void setParent(Parent parent)
{
this.parent = parent;
}
public Parent getParent()
{
return this.parent;
}
public String getName()
{
return "CHILD";
}
}

