.NET to Java serialization/deserialization compatibility

妖精的绣舞 提交于 2020-01-10 05:22:06

问题


Are there any compatibility issues to take care of when serailizing an object in .NET and then deserializing in Java?

I am facing problems in de-serializing an object in java which has been serialized in .NET

Here is the detailed problem statement:

In .NET platform i have a cookie. 1. Cookie is serialized 2. then it is encrypted using Triple DES algo. 3. Send it across to Java application

In Java platform 1. Decrypt the cookie using Triple DES which gives some bytes 2. Deserialize the bytes using something like

new ObjectInputStream( new ByteArrayInputStream(byte[] decryptedCookie)).readObject();

The exception stack trace I get is: java.io.StreamCorruptedException: invalid stream header: 2F774555 at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.(Unknown Source)


回答1:


The WOX serializer provides interoperable serialization for .Net and Java.




回答2:


If you serialize in xml then you shouldnt face any problems de-serializing in java since at worse you have to write your own bit of code to reconstruct the objects.




回答3:


The way java and .Net serialise to binary differs. How does one know the objects of the other e.g. .Net will have Dictionaries and Java Maps? (plus the bnary representation of a string might differ.

You have to use some data format that both understand and code to do the object mappings. Thus the above answers mentioning XML and WOX. I have worked with internal company produces as well.



来源:https://stackoverflow.com/questions/1303792/net-to-java-serialization-deserialization-compatibility

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!