public class FooImpl implements java.io.Externalizable {
private String message;
public String getFoo() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
private Object writeReplace() throws ObjectStreamException {
System.out.println("writeReplace invoked");
return this;
}
private Object readResolve() throws ObjectStreamException {
System.out.println("readResolve invoked");
return this;
}
public Object serialize() throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
}