Serialization is built into java. For most classes, you can simply implement java.io.Serializable
, and your classes become magically serializable. Then you can use java.io.ObjectOutputStream
it java.io.ObjectInputStream
to read and write your objects.
If you require custom serialization, add the following methods to the class to override serialization behavior. They must match these signatures exactly :
private void writeObject(ObjectOutputStream out) throws IOException {
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
}