Code example for ObjectStreamField

0
 
    private static class SerialPersistentFields implements java.io.Serializable {
        private static final String SIMULATED_FIELD_NAME = "text";
 
        private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
                SIMULATED_FIELD_NAME, String.class) };
 
        public int anInstanceVar = 5;
 
        public SerialPersistentFields() { 
            super(); 
        } 
 
        private void readObject(java.io.ObjectInputStream in)
                throws java.io.IOException, ClassNotFoundException { 
            ObjectInputStream.GetField fields = in.readFields();
            anInstanceVar = Integer.parseInt((String) fields.get(
                    SIMULATED_FIELD_NAME, "-5"));
        } 
 
        private void writeObject(java.io.ObjectOutputStream out)