views:

699

answers:

2

I want to send complex data from my android to a remote server via TCP-sockets. I know that I need to serialize the Objects. In Android this is done via parcelable. But this is an android specific interface and the server only knows the serializable interface. Also vice-versa android doesn't know a serializable interface.

Both the android and the server must "know" the object but they are implemented in two different ways (server--> serializable, android --> parcelable)

How do I use these interfaces properly, so that I can send Objects via TCP to the server successfully?

+1  A: 

We had the same issue here at work and we switched to JSON. Maybe you should consider doing the same?!

Edit: Android does know the Serializable interface. How could I forgot...

WarrenFaith
+2  A: 

Why not use Simple XML serialization, works with both Android and Java 1.5+. Its located at the following site.

http://simple.sourceforge.net

Also, the framework is fairly small and suitable for mobile platform (approx 270K with no dependencies). And it much more performant than most XML serialization or binding frameworks.

ng
XML is too slow
Have you based this on a benchmark of some form. Simple is light years a head of XStream and other such XML frameworks in terms of performance. In fact I just did a test on a very large object graph I had already been persisting with Simple, comparing it with Java object serialization. The read performance of Simple was 1.4 seconds to read the object, Java object serialization with ObjectInputStream took 2.2 seconds, much slower. The only negative using Simple is the resulting object was 16,596 KB to write in XML and the Java serialization result was 9,896 KB. Simple was much faster though.
ng