Q:

Serialization of static fields with readResolve()

When I serialize an object I want to also take a "snapshot" of the static fields.
Is the following code a good practice ?
public class ClassA implements Serializable {

    private int num1;
    private static int num2 = 5;

    private int num2Saver;

    public int getNum1() {
        return num1;
    }

    public void setNum1(int num1) {
        this.num1 = num1;
    }

    public static int getNum2() {
        return num2;
    }

    public void setNum2(int num2) {
        ClassA.num2 = num2;
        num2Saver = num2;
    }

    private Object readResolve(){
        num2 = num2Saver;
        return this;
    }
}

(notice that in order to set the static field you have to go through an instance )

A:

Maybe you could implement the dedicated private void writeObject(ObjectOutputStream out) throws IOException; method to customize your serialization when you write your objects. Then you have the private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException; when you have to deserialize your objects.  
This way you can customize your serialization/deserialization process.
See http://java.sun.com/developer/technicalArticles/Programming/serialization/.

