From: Tim Wilkinson (tim@transvirtual.com)
Date: Mon Feb 08 1999 - 22:14:06 EST
Just so eveyone know, I've decided to handle serialization via an inner
class - the inner class implement the fields as JDK expects, and has two
methods to load and unload the data into them.
For example, in Hashtable (which I've done as an example though it's not
strictly necessary) we have the following:
/*
* JDK compatible serialization
*/
class DefaultSerialization {
private float loadFactor;
private int threshold;
private void readDefaultObject() {
Hashtable.this.loadFactor = loadFactor;
Hashtable.this.rehashLimit = threshold;
}
private void writeDefaultObject() {
loadFactor = Hashtable.this.loadFactor;
threshold = Hashtable.this.rehashLimit;
}
}
The beauty of this is that it kills two birds with one stone - provides
a way to specify the class fields "JDK-like" without screwing with the
true class representation, and provides a way to send the right data
out. The downside is that every readObject/writeObject operation
requires the inner class to be created (and they're very short lived) -
ah well say I. The serialization systemlooks for the inner class and
uses that if it finds it, otherwise it just falls back on the default
mechanism.
Comments?
Of course, I still don't know how to deal with radically different
classes (such as java.awt.Component).
Cheers
Tim
-- Tim Wilkinson Tel: +1 510 704 1660 Transvirtual Technologies, Inc., Fax: +1 510 704 1893 Berkeley, CA, USA. Email: tim@transvirtual.com
This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:58:02 EDT