Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Serializing an object with out implementing Serializable

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 71715
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 . . .
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't play dumb with me! But you can try this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic