See we're all here on Sunday... gotta change my life!

@Bernd: java.util.Calendar is a good example of an implementation.

The serialization pattern changed between JVMs but Sun had to make the backward 
compaitable. The answer was a standard writeObject() method and a readObject() 
method that decide if the old version was coming or a new one, which is 
basically the problem you want to solve.

 /**
  |      * Reconstitutes this object from a stream (i.e., deserialize it).
  |      */
  |     private void readObject(ObjectInputStream stream)
  |          throws IOException, ClassNotFoundException
  |     {
  |     final ObjectInputStream input = stream;
  |         input.defaultReadObject();
  | 
  |         stamp = new int[FIELD_COUNT];
  | 
  |         // Starting with version 2 (not implemented yet), we expect that
  |         // fields[], isSet[], isTimeSet, and areFieldsSet may not be
  |         // streamed out anymore.  We expect 'time' to be correct.
  |         if (serialVersionOnStream >= 2)
  |         {
  |             isTimeSet = true;
  |             if (fields == null) fields = new int[FIELD_COUNT];
  |             if (isSet == null) isSet = new boolean[FIELD_COUNT];
  |         }
  |         else if (serialVersionOnStream >= 0)
  |         {
  |             for (int i=0; i<FIELD_COUNT; ++i)
  |                 stamp = isSet ? COMPUTED : UNSET;
  |         }
  | 
  |         serialVersionOnStream = currentSerialVersion;
  | 
  |     // If there's a ZoneInfo object, use it for zone.
  |     try {
  |         ZoneInfo zi = (ZoneInfo) AccessController.doPrivileged(
  |             new PrivilegedExceptionAction() {
  |                 public Object run() throws Exception {
  |                     return input.readObject();
  |                 }
  |             });
  |         if (zi != null) {
  |             zone = zi;
  |         }
  |     } catch (Exception e) {
  |     }
  | 
  |     // If the deserialized object has a SimpleTimeZone, try to
  |     // replace it with a ZoneInfo equivalent (as of 1.4) in order
  |     // to be compatible with the SimpleTimeZone-based
  |     // implementation as much as possible.
  |     if (zone instanceof SimpleTimeZone) {
  |         String id = zone.getID();
  |         TimeZone zi = TimeZone.getTimeZone(id);
  |         if (zi != null && zi.hasSameRules(zone) && zi.getID().equals(id)) {
  |             zone = zi;
  |         }
  |     }
  |     }

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917536#3917536

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3917536


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to