views:

163

answers:

1

I have a distributed application. The client and the servers share some common libraries. The client has to be compiled with a JDK 5 compiler or with target=1.5 (run anywhere also on PowerPC and CoreDuo Macs). But I would like to use SE 6 features in the server-only code.

Is it ok to compile the common libraries twice - once with a JDK 5 and once with a JDK 6 and serialize objects on the client side using class files compiled with JDK 5 and deserialize them on the server side with class files compiled with a JDK 6 and vice versa? Or will that break serialization?

What is the best practice for building libraries that should run with code that is compiled with different JDK versions?

+5  A: 

If you explicitly define your serialVersionUID, it should be possible to serialize and deserialize in different JVM versions. That's sort of the point of defining it; see the spec:

Note - It is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected serialVersionUID conflicts during deserialization, causing deserialization to fail.

Michael Myers