Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > renaming fields in serialised objects

Reply
Thread Tools

renaming fields in serialised objects

 
 
Roedy Green
Guest
Posts: n/a
 
      07-02-2005
If I rename a field in a serialised object, e.g fileName to filename,
is there some sample code somewhere so that I can still read the old
version objects?

I don't know when I read a file whether they have been converted the
new name.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      07-03-2005
On Sat, 02 Jul 2005 14:32:37 +0000, Roedy Green wrote:

> is there some sample code somewhere so that I can still read the old
> version objects?
>
> I don't know when I read a file whether they have been converted the
> new name.


AFAIK this is one of the reasons why serialization should not be used as
persistent storage. There is no easy way to do this as far as i know,
except for almost implementing the serialization protocol again in your
readObject, and changing this one name.

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


 
Reply With Quote
 
 
 
 
Joan
Guest
Posts: n/a
 
      07-03-2005

"Roedy Green" <look-> wrote in message
news:...
> If I rename a field in a serialised object, e.g fileName to filename,
> is there some sample code somewhere so that I can still read the old
> version objects?


I read about this somewhere, but forget the details. Short answer
is that you can. It has to do with the serialver command and the
long serialVersionUID
that it produces.

>
> I don't know when I read a file whether they have been converted the
> new name.
>
>
> --
> Bush crime family lost/embezzled $3 trillion from Pentagon.
> Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
> http://www.infowars.com/articles/us/...s_rumsfeld.htm
>
> Canadian Mind Products, Roedy Green.
> See http://mindprod.com/iraq.html photos of Bush's war crimes



 
Reply With Quote
 
Tom Dyess
Guest
Posts: n/a
 
      07-03-2005
"Joan" <> wrote in message
news:MaCdnfoRdvkyoFrfRVn-...
>
> "Roedy Green" <look-> wrote in message
> news:...
>> If I rename a field in a serialised object, e.g fileName to filename,
>> is there some sample code somewhere so that I can still read the old
>> version objects?

>
> I read about this somewhere, but forget the details. Short answer
> is that you can. It has to do with the serialver command and the
> long serialVersionUID
> that it produces.
>
>>
>> I don't know when I read a file whether they have been converted the
>> new name.
>>
>>
>> --
>> Bush crime family lost/embezzled $3 trillion from Pentagon.
>> Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
>> http://www.infowars.com/articles/us/...s_rumsfeld.htm
>>
>> Canadian Mind Products, Roedy Green.
>> See http://mindprod.com/iraq.html photos of Bush's war crimes

>
>


Yes, I was reading up on this as well. AFAIK, the long serialVersionUID is a
unique identifier for the class structure. This is similar to a GUID for a
com object and is used for versioning. If the serialVersionUID is different
from when the obejct was persisted, then the object is no longer compatable
with the data. Conversely, if your serialVersionUID is the same, Java will
attempt to load the persisted object. I'm not sure if the case difference
would render the object unreadable. If you don't explicitely create a
serialVersionUID, Java will create one on the fly based on classname and
structure using reflection.

Here is some more info:

http://www.codecompile.com/CodeCompi...id=sr&id=11318
http://www.codecompile.com/CodeCompi...id=sr&id=11818

--
Tom Dyess
OraclePower.com


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-03-2005
On Sat, 2 Jul 2005 20:21:54 -0500, "Joan" <> wrote
or quoted :

>
>I read about this somewhere, but forget the details. Short answer
>is that you can. It has to do with the serialver command and the
>long serialVersionUID
>that it produces.


I discovered to complicate this that not only is each serialisable
base class supposed to have a id version number, but every individual
subclass as well. I guess the idea is you can rescue the base class
info even if you can't rescue the modified subclass.


I guess the way you do it is the way you would in the old cobol days.

You have the old record layout and the new and you write a utility
that does a move corresponding (faked in java with a utility)
to copy the fields across. You write one of these to convert from v1
to v2, v2 to v3 etc. When you open a file you read the first record
that tells the versionlayout of the file, then apply the appropriate
updater before continuing processing. I worked with a scheme like
this in C for educational software so end users could restore old
datafile backups safely.

Some how though you have to have the same class name used for both old
and new code. I guess you implement an interface on both and load
them with separate class loaders??

This is something than needs automation.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-03-2005
On Sat, 2 Jul 2005 23:02:19 -0400, "Tom Dyess" <> wrote
or quoted :

>If you don't explicitely create a
>serialVersionUID, Java will create one on the fly based on classname and
>structure using reflection.


That one is very fragile IIRC. It seems that even adding methods
nothing to do with the data fields changes the generated number.
Every time you compile your serialised objects stop working.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StateServer - when is the session serialised? Rob Nicholson ASP .Net 2 07-03-2008 11:22 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Serialised applets using the Sun Plug-in Thomas Hawtin Java 2 12-03-2006 12:32 AM
Why it is dumb ideas to store permanent data in serialised files Roedy Green Java 7 02-13-2006 08:56 AM
Demoting and Promoting Serialised Objects Roedy Green Java 4 07-10-2005 04:34 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57