user283494
user283494

Reputation: 1907

Android, Serializable/Parcelable problem in client-server app

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?

Upvotes: 1

Views: 2325

Answers (3)

tomwhipple
tomwhipple

Reputation: 2850

According to http://developer.android.com/reference/android/os/Parcel.html it is not appropriate to use a parcel for persistant (or network) serialization:

Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

Upvotes: 0

ng.
ng.

Reputation: 7189

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.

Upvotes: 2

WarrenFaith
WarrenFaith

Reputation: 57682

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...

Upvotes: 1

Related Questions