Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to make non-serializable object serializable?

Status
Not open for further replies.

chuq2001

Programmer
Jul 15, 2002
24
US
I'm sending data by way of an ObjectOutputStream, but the object I want to send does not implament Serializable. Can I get it to be Serilaizable?

Thanks
Chuck T.
 
Nope, not unless you change the class to implement the Serializable interface.
 
Assuming you cannot change the class its implementation, and if you have access to the object's contents from the outside and are able to reconstruct it based on those contents, you could make a helper class that serializes and deserializes the object for you.

This helper class would be serializable, and upon restoring it you would call one of its methods to "reconstruct" the object that you want.

HTH
Pieter
 
For example:
The Subject is serializable but credential inside is not. how can I go bout doin it?


anyone pls help

angktwap


 
If your class is serializable (in that it implements the Serializable interface, and has a public constructor), yet it contains within it other objects that are not serializable - then you cannot serialize that object.
 
Is there another way for me to sent this object to another application?

thanks
 
No. To send objects over the network, you must serialize them into byte code (with perhaps the exception of transforming beans into xml representation - but this wouldn't work in your case).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top