2

I have a java program (jar) that serialize a class to file with ObjectOutputStream. I need to use this part of the program inside a .NET project and to do so i have converted the jar to a .NET dll with ikvmc.exe. Everything works fine but the serialized file differs in some parts from that serialized directly using the java program. Do you have some suggestions to have the same identical serialized file?

Luca Looz
  • 271
  • 3
  • 15
  • Is there *no* way you can change the Java code to serialize to a more portable format? – Jon Skeet Oct 10 '12 at 20:26
  • No i can't. I have to send those serialized file to a java web service that's not mine. – Luca Looz Oct 11 '12 at 06:50
  • A web service which uses *Java binary serialization* as its input format? Ewww, that's nasty. You have my sympathies :( To be honest, you might be best off running a local Java binary (not IKVM, just normal Java) which takes a saner form of input (e.g. JSON) and is *just* responsible for serialization. – Jon Skeet Oct 11 '12 at 08:15
  • Yes, i have created a my java binary callable with paramaters (pathinput, pathoutput etc) that import the jar library and uses its methods. Now i have to simply call, with Process class in .NET, my java binary. – Luca Looz Oct 11 '12 at 09:31
  • What you means with file differ? Do you receive some exceptions on deserialize? – Horcrux7 Oct 11 '12 at 19:29

1 Answers1

1

Java serialization and deserialization work only good if you use the same compiled classes on both side. If you serialize classes of the Java VM runtime then you should use exact the same VM version on both sides. In the other case the classes can have different serialVersionUID.

Depending on the IKVM version it depends on different OpenJDK version. For example based version 7.x on OpenJDK 1.7.0.

Horcrux7
  • 23,758
  • 21
  • 98
  • 156
  • The java program that i need, serialize a Vector object that contains some other custom objects. Maybe serializing with OpenJDK 1.7 and Sun 1.7 generate different files because the Vector class has different serialVersionUID, is correct? – Luca Looz Oct 12 '12 at 06:53
  • The differences between OpenJDK and Sun/Oracle JDK are marginal. The differences between 1.6 and 1.7 can be larger. But the Vector class is not a problem. Without the exact error message that you receive the answer is like reading a crystal ball. – Horcrux7 Oct 12 '12 at 21:32