| Author |
Object Serialization
|
Venish Joe
Greenhorn
Joined: Mar 01, 2006
Posts: 14
|
|
I have a java code which creates an object for a class. Now I have another instance of the same application where I need the object created during the first instance. I tried to use Object Serialization but the object which I try to Serialize is not Serializable [It is a third party lib and I can't change the source]. Is there any possible way to overcome this problem? Please suggest me some solutions. Even its fine if you tell me how to access the object without using Serialization. Thanks Venish Joe
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
One thing you might try is to create a subclass of the original and have the subclass implement Serializable. One drawback to this is that if the original contains member variables which are object references and their class definitions are not Serializable, then those members won't be serialized. Here is an example.
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
Serialization is a more generic term than Java Serializable. That is, you can use other techniques to turn an object into a format you can transmit and then turn that back into an object. There are a bunch of tools around to read all the public variables or call all the getWhatever methods to get data from an object and generate XML or some proprietary format, and then convert back. Google for "java marshaller" or "java xml marshaller" and find too many choices! You may find that your 3rd party class won't play with any of these tools because of private variables or something so you may have to write your own marshall and unmarshall routines just for this thing.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
ak pillai
author
Ranch Hand
Joined: Feb 11, 2006
Posts: 288
|
|
You can try and use JibX to marshal the third party object to XML and send it across network or unmrshal the XML back to your own serializable object. I am currently using JibX, and quite impressed with its performance and flexibility. JIBX Home
|
java j2ee job interview questions with answers | Learn the core concepts and the key areas
|
 |
Venish Joe
Greenhorn
Joined: Mar 01, 2006
Posts: 14
|
|
Thank you very much for all the response. Keith Lynn, The lib contains refrences to objects which are not serializable. So creating a sub class won't work. Stan James / ak pillai, I have downloaded some marshallers and I am trying to implement them in my application. Let me update once that has been finished. Thanks & Regards Venish Joe
|
 |
Venish Joe
Greenhorn
Joined: Mar 01, 2006
Posts: 14
|
|
Apologies for the delayed reply. The marshallers are not working for that object. Always throws an exception. Isn't there any other way to access the object? Thanks Venish Joe
|
 |
 |
|
|
subject: Object Serialization
|
|
|