1

Html5 supports for storage only strings for key AND value.

Which approaches are known to unbreak this limit, especially in the context of GWT?

Are there libraries or framework dealing with this situation?

Is some code of the standard libraries useful to do this?

EDIT

I would like to do the most natural approach:

get/request data form cache/storage, if not available then request it via GWT-RPC

stefan bachert
  • 9,413
  • 4
  • 33
  • 40

3 Answers3

2

AutoBeans are pretty great for this - by just defining a bean interface and a factory interface AutoBeans will work out the rest of the details of how to turn your data into JSON (or some other stringy data) and back again.

This question/answer discusses how this could be addressed both with JavaScriptObject subclasses and with AutoBeans: Cache in GWT app/widget with HTML5 localStorage

If possibly encoding several different types, an answer that came up a few months ago might be helpful: Parsing JSON objects of unknown type with AutoBean on GWT

If you are working with data from RPC, things get a little trickier. First, you have to consider that the RPC serialization mechanisms are wired up for one way travel (though there are two of them, one for each direction) to prevent some server->client objects from being deserialized on the server for security reasons. Second, remember that every time models change or RPC interfaces change, the server and the client no longer see eye-to-eye, as the serialization format has been modified - your app's localStorage cache would have data that could no longer be read after some updates.

Community
  • 1
  • 1
Colin Alworth
  • 17,801
  • 2
  • 26
  • 39
  • I would like to do the most natural approach: get data form cache/storage, if not available then request it via RPC. So I think AutoBeans will not into this szenario. I intend to investigate RPC. The two way aspect does not hurt me. The update issue ith localStorage seems very manageable to me. – stefan bachert May 10 '12 at 07:36
  • If you happen to be using RequestFactory, an alternative to RPC, it already uses autobeans, so is easier to serialize objects. – Colin Alworth May 10 '12 at 13:12
1

You can try GWT-Storage https://github.com/seanchenxi/gwt-storage. It can help you to store Object value in HTML Storage.

Xi CHEN
  • 271
  • 1
  • 6
0

You can serialize your data to XML and then deserialize back to a POJO.

http://x-stream.github.io/tutorial.html

Well, maybe it's not that easy to use a library in GWT.

facundofarias
  • 2,973
  • 28
  • 27
André Onuki
  • 428
  • 2
  • 12