But a Container is not required to use serialization
A container is required to migrate Serializable attributes
Session Migration and Serialization
A container is required to migrate Serializable attributes(which assumes that all instances variables within the attribute are either Serializable or null.
But a Container is not required to use serialization as the mean of migrating HttpSession Object
What does that mean to you? Simple make sure you attribute class types are Serialzable and you never have to worry about it.
But if the yare not Serializable (which could be because on of the attribute object's instance varibales i snot Serializable), have your
attribute object class implement HttpSessionActivationListener and use the activation/passivation callsback to work around it.
The container is not required to use Serialization, so there's no guarantee that readObject() and writeObject() will be called on a
Serializable attribute or one of its instance variables!
If you are familiar with Serialization, you know that a class implements Serializable can also choose to implement a writeObject()method, called by the
VM container whenever an object is serialized and a readObject() method, called when an object is deserialized. A Serializable object can use these
methods to for example, set non-Serializable fields to null during Serialization(writeObject() and then restore the fields during deserialization(readObjet()).
But the methods won't necessarily be called during session migration! So if you need to save and restore instance variable state in your attribute, use
HttpSessionActivationListener, and use the two event calledbacks(sessionDidActivate() and sessionWillPassivate()) the way you would use readObjet()
and writeObject()