开发者

Sending objects from GAE PersistenceManger to Android

I am writing an Android app that talks to a Google App Engine server. The server holds persistent data, which it stores and fetches using PersistenceManager. The way I have this set up now is as follows:

  • A @PersistenceCapable class on the server called StoredThingToRemember has the information to remember, as well as some GAE object persistence jazz.
  • When the Android client wants to fetch a ThingToRemember, it sends an HTTP request to the server, which fetches a StoredThingToRemember from a PersistenceManager, converts it to a ThingToRemember implements Serializable, serializes it as a byte[], then sends it in an HTTP response.
  • The client unserializes the ThingToRemember and uses it.
  • 开发者_C百科

This works, but it seems wonky. Ideally, I would like to serialize and send the StoredThingToRemember itself. Unfortunately, that seems to require putting all the GAE object persistence classes in the Android app, which seems silly and wasteful.

What is the correct way to grab an object from GAE persistence and then use that object in an Android app?


Using serialization formats for transmitting data is generally fairly risky - they're usually not designed with transmission across trust domains in mind. Further, by doing so you're locking yourself in - both your client and your server will always have to be written in Java. Any further clients will either have to be written in Java, or will require a whole new interface.

Instead, you should serialize to a language-independent format, such as XML or JSON.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜