Reputation: 2571
How can I pass a non-serializable object over a network?
Upvotes: 2
Views: 177
Reputation: 3994
Use a library like XStream. XStream in particular will turn your code into xml which can then be sent across the network and reconstituted on the other side. There are many alternatives to the Serialization mechanism built into Java and most do not require the Serializable interface.
Upvotes: 0
Reputation: 115388
If there is a serious reason that the object is not serializable you cannot pass it over network. For example if your class contains members that cannot be serialized (streams, threads etc.)
But if the reason that the class is not serializable is that its author just did not mark it this way and you do not have access to class' source code to make it serializable you have the following ways.
implements Serializable
and then send it over network.Upvotes: 2