This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've been working on a framework for sometime now (OortCloud) that deals with mapping, wiring and filtering Objects to UI components. I recently read a few posts here at the O'l JavaRanch and it raised a few questions that I cant seem to answer through research.
Mainly: Why must I Serialize every Pojo that will be used as a session scoped object throughout the framework? I mean I've read that it's a rule to do so, but... why? The way I have it now is to distribute these objects through a singleton (Enum factories which are already serialized) creating new instances of defined Objects when requested by a new session. Then I store said instances in a SessionBean container (also serialized) . When one SessionObject needs another I pull it from the Session Container. The only answer I can think of is in the event that the container is sent to another VM?
I think your last statement is exactly one main reason to make session scoped objects serializable! If you're working in a clustered environment with multiple servlet containers or application servers running in different JVM (probably on different machines) it's likely that session scoped data are migrated/replicated to other nodes because every container should of course see identical session data.
So in the above case where there is a container for these Objects (OBJMAP) which resides in a serialized object. would all of the objects in that map be serialized when the VM is restarted automagic like? [ December 02, 2008: Message edited by: Richard Corbin ]
I'm not sure if I understood you correctly, so please tell me if I got it wrong
If something should be serialized by the container or any other framework or API it's usually the entire object graph which gets automatically serialized. So in your example it's not only the map itself which is serialized but also its content, i.e. the objects you have put in it. Strictly speaking the JVM _TRIES_ to serialize the whole object graph. But for this to work correctly each object/class down the nested object tree has to be serializable! Often this is not a problem if your own classes are composed of primitive types or JDK classes which are serializable but in general it's not sufficient to put an object in another serializable object in order to make this object serializable, too. I hope this explanation was understandable
Joined: Nov 22, 2008
I started reading up on Serialization and I (Think I) get it now. I was under a few misconceptions about Serialization in general. Thinking that an object that was cast as an inner Class of a serialized Object inherited its serialization. when I asked this question over at (sun.com java forums) I got a confusing response, and the usual catty quip that is pleasantly absent here at JavaRanch