This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Serializing an object with out implementing Serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Serializing an object with out implementing Serializable" Watch "Serializing an object with out implementing Serializable" New topic
Author

Serializing an object with out implementing Serializable

Jerry Ragland
Ranch Hand

Joined: Apr 26, 2005
Posts: 33
I am not sure whether its an intermediate question...
Is there any way to make an object serializable or writing its current state in OutputStream with out implementing the Serializable interface.
I came across Object's clone method and it use to make an exact copy of the object can that be used to do perform that operation.

Thanks in advance,
Jerry.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
No.


If you want to serialise an object it must implement the tagging Serializable interface.
Cloning gives you another copy of an objcet so you can play with it without altering the original fields. It does not provide for persistence, does not allow you to write with an OutputStream, and does not allow you to send the object across a network. You could however serialise the clone . . .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
if your object has JavaBean characteristics, then you could use the java.beans.XMLEncoder/Decoder to serialize the object to an XML representation. It's not applicable everywhere where binary serialization or cloning is, but it has its own advantages.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializing an object with out implementing Serializable
 
Similar Threads
Creation of objects and serialzation
How to pass HttpSession to SessionBean?
Marker Interface
serialization in java
HttpSessionActivationListener example