2 Replies Latest reply: Oct 28, 2010 6:00 PM by EJP RSS

    Serialization on inherited objects

    805937
      Is there a way to make entire base classes transient for objects that extend other classes? This base class cannot be serialized. Can the super class be initialised by calling the default constructor before deserializing the sub class in the writeObject/readObject call?
        • 1. Re: Serialization on inherited objects
          796440
          802934 wrote:
          Is there a way to make entire base classes transient for objects that extend other classes?
          It's not clear what you're saying. Transient applies to variables, not classes. If a given class is Serializable, then all its descendants are as well.
          This base class cannot be serialized. Can the super class be initialised by calling the default constructor before deserializing the sub class in the writeObject/readObject call?
          Huh???
          • 2. Re: Serialization on inherited objects
            EJP
            Is there a way to make entire base classes transient for objects that extend other classes? This base class cannot be serialized.
            Just don't declare it as Serializable and don't have it inherit from anything that is, and if you need extra protection don't provide access to any fields so that derived classes can't roll their own serialization of your base class's state.
            Can the super class be initialised by calling the default constructor before deserializing the sub class in the writeObject/readObject call?
            That happens automatically if the base calss isn't serializable. That's why it is required to have an accessible no-args constructor.

            You should read the Object Serialization Specification. It's all covered there.