Just wanted to know if there is any mechanism via which we can make sure the De-serialization was successful.

Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958

73

posted Apr 07, 2014 08:45:55

0

In a different JVM? You'd have to put in place some communication protocol of your design.

Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141

posted Apr 09, 2014 23:11:23

0

Thanks for your reply.

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

Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958

73

posted Apr 10, 2014 00:31:03

0

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.

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

Joined: Mar 22, 2005
Posts: 42958

73

posted Apr 12, 2014 04:23:45

0

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).

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

Joined: Mar 22, 2005
Posts: 42958

73

posted Apr 12, 2014 06:16:39

0

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.