Can a serialized simple java object be deserialized in C #?

Assuming that all fields of the java class are java primitives, if such an object was serialized, is it possible to deserialize it using C # into an instance of the "equivalent" C # class?

Is the opposite possible - C # in java?


I understand that there are many language agnostic formats, such as XML, that you can use to do this work. I'm more interested in whether using my own serialized data is possible.

+6
source share
4 answers

Serialized stream formats are available. I think you can easily write a class to parse the byte stream and create the required class in C #.

Article showing serialized format: http://www.javaworld.com/community/node/2915

+5
source

It is impossible, at least, not to use the native serialization libraries that both structures provide, as indicated in this previous SO post.

If you want to serialize / deserialize a serial language, you can refer to XML ( XSTream for Java, XStream-dot-net for C #) or WOX :

WOX is an XML serializer for Java and C # objects. In other words, WOX is a library (woxSerializer.jar for Java and woxSerializer.dll for C #) for serializing Java and C # objects in XML and vice versa.

+1
source

WOX will be useful to ensure compatible serialization.
it can serialize/deserialize Java/C# objects into/from standard XML (platform independent)

+1
source

If you're fine with including another dependency, you might consider using a database of objects such as db4o for the job. I have not tried this myself, but according to the Wikipedia article,

db4o uses a user-defined function called a "common reflector" to present class information when class definitions are unavailable, which allows it to be used in a mixed Java-.NET environment, for example, a Java client-.NET server and vice versa.

You can find more information about the reflection API mentioned above here and.

In short, this will lead to a system in which you store Java / C # objects in a (built-in) database (i.e. without a client-server architecture, but loading a single file containing the entire database) and extract C # / Java- objects from the database.

0
source

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


All Articles