Name: boT120536 Date: 02/08/2001 java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode) The JDK object streams use the read/writeClassDescriptor methods for two purposes. This makes overriding these methods very difficult. In the most common case these methods are used to describe the class of an object being serialized. In this case the class is always Serializable. This is important because the only public way to get a ObjectStreamClass is through ObjectStreamClass.lookup which will only return ObjectStreamClasses for Serializable classes. Using this one can then implement a version of writeClassDescriptor which sends the descriptor in a different way and a version of readClassDescriptor which receives this information and uses ObjectStreamClass.lookup to find or create the appropriate descriptor. There is however a less common use of read/writeClassDescriptor which makes overriding these methods much more difficult (though not quite impossible, see workaround below). When an instance of a Class object is serialized out it is handled specially and the stream ends up calling read/writeClassDescriptor for the class of which the Class object represents. In this case the class may not be Serializable (the Class object is an instance of java.lang.Class which is Serializable, but may represent some other class which is not a Serializable). Because the ObjectOutputStream uses default (package) access methods to construct the ObjectStreamClass to be written this poses no problem for an implementation of writeClassDescriptor. However a custom implementation of readClassDescriptor has no means of creating an ObjectStreamClass for a class which is not Serializable. This all makes the ability to override the read/writeClassDescriptor much less useful than it would otherwise be. It also seems to me to be part of a bigger question about serializing Class objects. It seems a little strange to allow this, that is what classloading is for. (Review ID: 110681) ======================================================================
|