Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deserialization

 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Deserialization is successful in another JVM2 then how does it notify the first JVM as "Deserialization is successful"
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't. Why do you think it should?
 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted to know if there is any mechanism via which we can make sure the De-serialization was successful.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a different JVM? You'd have to put in place some communication protocol of your design.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Can you tell me as what are the ways the serialized object is transferred to another JVM ?

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's built-in serialization classes (Object[In|Out]putStream and XML[En|De]coder) write to OutputStreams, from which you can obtain a byte[] - you can then use those in whichever way you see fit. Note that binary serialization frequently does not work if source JVM and target JVM have different versions, and XML serialization needs the transferred objects to be JavaBeans.
 
Claude Moore
Ranch Hand
Posts: 785
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Note that binary serialization frequently does not work if source JVM and target JVM have different versions..

Really ? Even for java built-in serialization / deserialization ?
As far as you know, what are circumstances under which default Java serialization / deserialization mechanism may fail ?

Thank you.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binary serialization relies on identical serialVersionUID, which can be different for the same class between different JVMs implementing the same Java version (say, JRockit 1.6 and OpenJDK 1.6), or different between two versions of the same JVM implementing different Java versions (say, OpenJDK 1.6 and OpenJDK 1.7), or sometimes even between two versions of the same JVM implementing different patch releases of the same Java version (say, OpenJDK 1.6.25 and OpenJDK 1.6.45).

http://www.mkyong.com/java-best-practices/understand-the-serialversionuid/ has some more information on that.
 
Claude Moore
Ranch Hand
Posts: 785
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read the article you suggested... In my working scenario, I Exchange dataobject from java client to java server in serialized form. I never run into any issue; do you think that may
be sufficient to provide my custom object with a serialUID to avoid issues ? By the way: of course, I have both client and server side the same version of objects.
If they are disaligned, an exception is surely going to be thrown.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a serialVersionUID helps make the version explicit, but it can also be source of problems - for example, if you forget to change it after making incompatible changes to a class.
 
Claude Moore
Ranch Hand
Posts: 785
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.
 
Oleg Glizerin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks it helped me 2
 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Oleg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic