Java serialization issues for different JVMs

Java serialization issues for different JVMs … here is a solution to the problem.

Java serialization issues for different JVMs

I’m having trouble using serialization in Java. I searched the web for a solution but haven’t found an answer yet.

The problem is like this – I have a Java library (I have the code, I export it to an archive before executing the code) and I need to use it with two different JVMs. One JVM on the server (Ubuntu, running Java (TM) JRE SE Runtime Environment (build 1.7.0_09-b05)) and the other on Android 2.3.3. I compiled this library with Java 1.6.

Right now, I’m

trying to import an object to the client that was exported from the server, but I’m getting this error:

java.io.InvalidClassException:
[Lweka.classifiers.functions.MultilayerPerceptron$NeuralEnd;;
Incompatible class (SUID):
[Lweka.classifiers.functions.MultilayerPerceptron$NeuralEnd; : static
final long serialVersionUID =-359311387972759020L; but expected
[Lweka.classifiers.functions.MultilayerPerceptron$NeuralEnd; : static
final long serialVersionUID =1920571045915494592L;

I did declare an explicit serial version UID on the class MultilayerPerceptron$NeuralEnd as follows:

protected class NeuralEnd extends NeuralConnection {
    private static final long serialVersionUID = 7305185603191183338L;
}

NeuralConnection implements the java.io.Serializable interface. If I execute serialver on MultilayerPerceptron$NeuralEnd, I receive the serialVersionUID of my declaration. So why did both JVMs change this value? Can you help me?

Thank you
Alberto

Solution

I don’t think there is a solution. Serialization doesn’t work between different JVM versions (Dalvik isn’t even a JVM…). Look for other solutions, such as JSON/XML object serialization.

Related Problems and Solutions