How to make somebody else's class serializable?

S

Shawn

Hi,

I am using somebody else's Class file, which is also used by many other
people. The class file doesn't implements interface Serializable. Now, I
"wish" to write/save the object and later read/retrieve it by using
object serialization.

It is hard to request somebody changing his class file just becasue it
is convenient for me. Since it has been so for many years. (I will try
to ask him too.) I am wondering if it is possible to achieve my purpose
solely by my coding effort.

Thank you very much.
 
T

Thomas Hawtin

Shawn said:
I am using somebody else's Class file, which is also used by many other
people. The class file doesn't implements interface Serializable. Now, I
"wish" to write/save the object and later read/retrieve it by using
object serialization.

If you can subclass it, you can read and write the data yourself from
readObject/writeObject.

If you need to pass values to the constructor, you can use
readResolve/writeReplace:

http://groups.google.com/group/comp.lang.java.programmer/tree/browse_frm/thread/88dca62e39be2a90/

Tom Hawtin
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Shawn said:
I am using somebody else's Class file, which is also used by many other
people. The class file doesn't implements interface Serializable. Now, I
"wish" to write/save the object and later read/retrieve it by using
object serialization.

It is hard to request somebody changing his class file just becasue it
is convenient for me. Since it has been so for many years. (I will try
to ask him too.) I am wondering if it is possible to achieve my purpose
solely by my coding effort.

Maybe you can use this:

http://www.javageeks.com/Papers/SerializableAdapter/SerializableAdapter.html

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top