dcsimg
Issue on ObjectInputStream's readFields()
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Piergiuliano_Bossi
Posted On:   Monday, September 22, 2003 07:51 AM

Hi, We're working on a system where the persistance is implemented serializing/deseralizing the 'System' object that contains all the domain objects we need to save (we use Prevayler ). We've added to each domain class the serialVersionUID field so that each time we do a data migration we add the method readObject with the code to initialize all the changed/added fields in the new version of Class. Here is the code of the System project to deserialize its fiels: private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { ObjectInputStream.GetField gf = stream.readFields(); HashMap oldUsers = (HashMap)gf.get("itsUse   More>>

Hi,


We're working on a system where the persistance is implemented serializing/deseralizing the 'System' object that contains all the domain objects we need to save (we use Prevayler ).

We've added to each domain class the serialVersionUID field so that each time we do a data migration we add the method readObject with the code to initialize all the changed/added fields in the new version of Class.
Here is the code of the System project to deserialize its fiels:


			
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField gf = stream.readFields();

HashMap oldUsers = (HashMap)gf.get("itsUsers", null);
if (oldUsers != null)
itsUsers = new ArrayList(oldUsers.values());
else
itsUsers = new ArrayList();
itsProjects = (Vector)gf.get("itsProjects", null);
}


To correctly initialize the fields of our System object we need to specify the exact order in which the fields should be deserialized (first itsUser and second itsProject, currently is the opposite) but I haven't found a manner to change the behavior of readFields().

There is a way to specify such a order?


Thanks a lot.


Giannanadrea

   <<Less
About | Sitemap | Contact