4

I'm planning on developing an app for android that requires a back-end server to sync data with other users of the app. I'm planning on writing this server in standard java running on a unix server.

I once did this directly between two android devices, in that case I just serialized all the data needed to be sent on both ends.

However I suspect that the format that Dalvik serializes to and Java SE's format are not compatible. Is this the case? And if it is, what are my alternatives? One thing that popped into my mind was sending raw xml over a socket, but if there are better alternatives I'll be glad to hear them.

Thanks.

700 Software
  • 85,281
  • 83
  • 234
  • 341
monoceres
  • 4,722
  • 4
  • 38
  • 63

6 Answers6

6

If you are doing a server then you should rely on something more standard like XML or JSON. I personally favor JSON. You shouldn't expect all your client to be Java friendly. Almost every mobile device support JSON. Look at Jackson library to generate your json. Then you can use Jackson again to deserialize your object.

The beauty of this solution is also stupid simple. You can look at the content by just just putting the request in your browser. Not so easy with binary data.

Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
  • Really looks like the best option. I'll try it out and see how it goes. Thanks. – monoceres Jan 24 '11 at 18:19
  • You're welcome. Look at Jackson ObjectMapper. You can serialize and deserialze. It's faster than using java's native ObjectInput/OutputStream. You can also use this solution to later create an iphone or any other mobile application. Finally, look at Jeresy (http://en.wikipedia.org/wiki/JAX-RS) which would help you on making RESTful webservices. – Amir Raminfar Jan 24 '11 at 22:46
3

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

I did have to convert TimeZone class to String and back because the TimeZone class in particular is not fully compatible (it tried transferring something in the sun. package which got ClassNotFoundException on Android).

Other than that I have been able to transfer objects from java.util collections and maps and from java.sql data types and of course the java.lang types String, Integer, etc..

700 Software
  • 85,281
  • 83
  • 234
  • 341
  • if you have specific serialization bugs, please report them at http://code.google.com/p/android/issues/entry (though in the specific case you mention here, it sounds like Sun's bug rather than ours! TimeZone's serialized form is supposed to just be the String Olson id.) – Elliott Hughes May 14 '11 at 01:20
2

You can try protobuf for serialization. It is said to be more efficient, and you won't be concerned about compatibility.

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

The resolution of this question hints that it is compatible.

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

If your object graph is pretty simple and if you are comfortable with JSON at all, Android has JSON support included and it would be easy to get support in Java SE. I tend to think of JSON as a good alternative for when XML or Java serialization seems to "heavy".

Bert F
  • 85,407
  • 12
  • 106
  • 123
1

Have a look at this benchmark. Kryo is the one I'm using. It supports creation of the custom binary serialization, which can be done in a way suitable for both Dalvik and JSE.

You may want to look at a related question, which provides additional discussion and links.

Community
  • 1
  • 1
01es
  • 5,362
  • 1
  • 31
  • 40
0

Protocol buffers would be a good format over the wire to consider.

I can't speak to the serialization of Dalvik.

rfeak
  • 8,124
  • 29
  • 28