• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Serialization  RSS feed

 
Venish Joe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Venish Joe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!