Using C # to serialize a Java deserializable object

I have two applications that need to talk to each other. App1 should be able to serialize an object that App2 can then deserialize. Easy done, right? Here is the problem; App1 is based on C #, App2 is based on Java. Therefore, App1 needs to write the file in Java binary file format. How can I do that?

As I see it, I have two options. Firstly, this is some way of serializing a Java object in C #, so App1 just creates the corresponding file. My other option would be to write a Java converter that reads in a file and populates the object accordingly and serializes the newly populated object. So a C # application would just have to write some sort of formatted text file, which then interprets.

I cannot make any changes to the Java application.

How to do it?

Update:

The Java application is already in the hands of clients, so changing the serialization scheme will result in incompatibility with existing client data. The Java application uses the native Java series to work with this object. Modifications to the Java application cannot occur.

A C # application uses protocol buffers to serialize its own data.

+5
source share
4 answers

The best answer is option 3: use a serialization scheme that neutralizes the language.

I am using javascript. Thrift is another option, protocol buffers, which, it seems to me, are more focused on RPC, but should also be used for serialization. XML or custom binary format will be other parameters.

: , , Java. , - , , , Java-, , Java- .

+7

" IKVM" -, . java - (.jar ..) .NET DLL. .

, - , CSV XML.

+1

XML. , /. Java, XML .

+1
source

It is best to write something that uses the Java Native interface. Not fun, but it will work.

You can do this directly using JNI (not fun, but doable), or there may be some tools that will generate code for you - see SWIG: http://www.swig.org/

You would call Java from C # to do the persistence for you.

+1
source

All Articles