• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object Serialization

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic