1 2 Previous Next 18 Replies Latest reply: Aug 16, 2010 10:28 AM by 843790 Go to original post RSS
      • 15. Re: Understand the overriding of writeObject() and readObject() to manually
        843790
        Hello,

        The main concern behind this post is "HOW CAN WE SERIALIZE THE NON-SERIALIZABE MEMBER OF A CLASS?"
        Like in above code "private MathOperation mathOperation = null;" is the reference variable of the class which is non-serializable but which is implemented by some body else and I don;t want to modify that file and want to make this field in my class serializable.

        Please help me I m in big time trouble.

        Thank for ur reply.
        • 16. Re: Understand the overriding of writeObject() and readObject() to manually
          843790
          Hello,

          The main concern behind this post is "HOW CAN WE SERIALIZE THE NON-SERIALIZABE MEMBER OF A CLASS?"
          Like in above code "private MathOperation mathOperation = null;" is the reference variable of the class which is non-serializable but which is implemented by some body else and I don;t want to modify that file and want to make this field in my class serializable.

          Please help me I m in big time trouble.

          Thank for ur reply.
          • 17. Re: Understand the overriding of writeObject() and readObject() to manually
            EJP
            Then you are stuck. You can't serialize classes that aren't Serializable. It's a contradiction in terms. Period. If the class is intended to be serialized, somebody is going to have to declare it appropriately. If you can't do that, or get it done, raise it as an issue with management. Not a Java problem.

            And polease stop multiposting. Your account will get blokced if this continues.
            • 18. Re: Understand the overriding of writeObject() and readObject() to manually
              843790
              ShivlakhanPatel wrote:
              Hello,

              The main concern behind this post is "HOW CAN WE SERIALIZE THE NON-SERIALIZABE MEMBER OF A CLASS?"
              Like in above code "private MathOperation mathOperation = null;" is the reference variable of the class which is non-serializable but which is implemented by some body else and I don;t want to modify that file and want to make this field in my class serializable.

              Please help me I m in big time trouble.
              As already said, you can't serialize that non-serializable object directly. But you can serialize a representation of it. In this case the object in question seems to be completely described by two integers. So write those two integers to the ObjectOutputStream. When you de-serialize, read the two integers and recreate the MathOperation from them.

              To do this you need to declare the MathOperation reference transient, meaning it will be skipped from the default serialization mechanism. Writing and reading of the two integers is done from the writeObject and readObject methods, respectively.

              Of course, for any of this to work SerializeMathOperationClass must implement Serializable to begin with.
              1 2 Previous Next