Connect Dalvik with Java SE

I plan to develop an Android application that requires a server to synchronize data with other users of the application. I plan to write this server in standard java running on a unix server.

I did this right between the two Android devices, in this case I just serialized all the data that needs to be sent at both ends.

However, I suspect that the format that Dalvik serializes and the Java SE format are not compatible. This is true? And if so, what are my alternatives? One thing that occurred to me in my head was to send a raw file through a socket, but if there are better alternatives, I will be glad to hear them.

Thanks.

+4
source share
6 answers

If you make a server, then you should rely on something more standard, for example XML or JSON. I personally advocate for JSON. You should not expect your client to be Java friendly. Almost every mobile device supports JSON. Take a look at Jackson to create your json. Then you can use Jackson again to deserialize your object.

The beauty of this solution is also stupidly simple. You can view the content simply by posting the request in your browser. Not so simple with binary data.

+6
source

I have successfully used data serialization between Android devices and servers.

I had to convert the TimeZone class to String and vice versa, because the TimeZone class in particular is not fully compatible (he tried to pass something in the sun. package sun. Which received a ClassNotFoundException on Android).

In addition, I managed to transfer objects from collections and maps java.util and from data types java.sql and, of course, types java.lang String , Integer , etc.

+3
source

You can try protobuf for serialization. They say that it is more efficient and you will not worry about compatibility.

You can also use some form of XML serialization (JAXB, XStream, XMLEncoder, etc.)

The resolution of this issue means that it is compatible.

+2
source

If your graphic object is pretty simple, and if you're comfortable with JSON, Android supports JSON support , and it would be easy to get support in Java SE. I tend to think of JSON as a good alternative when XML or Java serialization seems "heavy."

+1
source

Check out this test. Kryo is the one I use. It supports the creation of custom binary serialization, which can be done in a suitable way for Dalvik and JSE.

You might want to consider a question that contains additional discussions and links.

+1
source

Protocol buffers will be a good format compared to wiring.

I can not talk about Dalvik serialization.

0
source

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


All Articles