[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Upgrading ozone applications

> That sounds very interesting.
> If I don't use serialVersionUID - then what versionnumber are you thinking
> about ?

You'll need both, serialVersionUID and you own version number. The
serialVersionUID stays always the same. Because of this Java thinks the streamed
objects are always compatible to the current implementation.
The second version number is for you to control which version you've
got serialized.
> Do I need to have both versions of my object in scope ? E.g. can I read a
> version1 object out of Ozone and the 'externalize' it to my updated version
> 2 object ?
> Would you happen to know of a place where code like that can be studied in
> more detail ?

An example:

public class TestImpl extends OzoneObject 
         implements Test, Externalizable {
     // remains always 1
     static long serialVersionUID = 1L;

     // increase it if you added or removed a member
     static int subSerialVersionUID = 2L;

     // is member since version 1
     private String aMember;
     // a new member
     private HashMap bMember;

     // ... some methods ...
     public void writeExternal( ObjectOutput out ) 
         throws IOException {
         out.writeInt( subSerialVersionUID );
         out.writeObject( aMember );
         out.writeObject( bMember );

     public void readExternal( ObjectInput in ) 
         throws IOException {
         int version = in.readInt();
         aMember = (String)in.readObject();
         if (version == 1) { 
             // a deleted member from version 1
         if (version > 1) { 
             bMember = (HashMap)in.readObject();

I hope, this helps.

Best Regards,

Gerd Mueller                                    gerd@smb-tec.com     
SMB GmbH                                  http://www.smb-tec.com