Deserializing a Java serialized file in C #

I have a java project that serializes some objects and ints into a file with functions such as

ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeInt(RANK_SIZE); oos.writeObject(_firstArray); oos.writeObject(_level[3]); oos.writeObject(_level[4]); ... 

Now it’s hard for me to deserialize this file with C # (I tried BinaryFormatter ), since it, apparently, can only deserialize the whole file into one object (or arrays, but I have different objects with different lengths).

At first, I tried to transfer the creation of these files to C #, but failed. These files are small, and I do not have to generate them myself.

Do I need to change the way I create these files in Java, or can I deserialize it in some way?

+3
source share
3 answers

There is nothing in the standard .NET platform that can deserialize Java objects. Theoretically, you can use the Java serialization specification and write your own deserialization code in C #. But this would be a large and complex project, and I do not think that you will find many customers interested in using it.

Far, it would be much easier to change the way data is serialized to use a portable format: JSON or some form of XML. There are Java and C # libraries for working with such formats, and the total amount of effort will be several orders of magnitude less. I would prefer this second approach.

+10
source

Perhaps, at first glance, an anti-intuitive solution could be to serialize them into some generally accepted format, such as JSON? I'm not even sure that the binary format for serialized objects in Java is guaranteed to remain unchanged between versions of Java.

Jackson is my personal favorite when it comes to Java JSON libraries.

+5
source

http://www.ikvm.net/ IKVM can do it perfectly.

+3
source

Source: https://habr.com/ru/post/950043/


All Articles