JDK-4180466 : Why is java.util.Observable class not serializable.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1.5,1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1998-10-10
  • Updated: 2016-04-20
  • Resolved: 2003-06-23
Related Reports
Relates :  
Description

Name: tb29552			Date: 10/10/98


The following paragraph is a taken from JDK1.1.6
class API specification for tha class java.io.ObjectOutputStream.

"Serialization does not write out the fields of any object that does not
implement the java.io.Serializable interface. Subclasses of Objects that are
not serializable can be serializable. In this case the non-serializable class
must have a no-arg constructor to allow its fields to be initialized. In this
case it is the responsibility of the subclass to save and restore the state of
the non-serializable class. It is frequently the case that the fields of that
class are accessible (public, package, or protected) or that there are get and
set methods that can be used to restore the state. "

I want to create a class which extends from java.util.Observable and
implements java.io.Serializable interface.  From the above specification
I cannot serialize the Observable class because:

1.It does not implement Serializable interface.

2.All it's members (obs Vector) are private so I cannot access
them to write to the stream myself.
(Review ID: 34853)
======================================================================

Comments
EVALUATION This class is no longer under active development. It is largely unused in the JDK, and has, for the most part, been superseded by the 1.1 Beans/AWT event model. Generally speaking, we're loath to make serializable: abstract classes, interfaces, and classes that are designed solely to be extended. Doing so places a burden on all who extend/implement the class/interface. On the other hand, it is somewhat unfortunate that it's pretty much impossible to have a subclass of Observable be serializable. I'd like some more information as to why the reporter wants to implement a serializable subclass of Observable before deciding how to proceed on this one. joshua.bloch@Eng 1998-11-11 The best solution is probably to to provide protected accessor methods to obtain the list of observers and to replace the current list with a given list. Acessor methods already exist for the changed flag. We'll try and do this in the next upgrade release. joshua.bloch@Eng 1999-02-04 Observable has fallen into disuse and is no longer under active development. ###@###.### 2003-06-23
04-02-1999