Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using RPC serialization/deserialization mechanism built in GWT

I am developing GWT offline application using HTML5 Local Storage. I would like to cache/store the transfer objects using com.google.gwt.storage.client.Storage (introduced in version 2.3). But the problem is that as for now (version 2.3) the Storage can only save the string values.

Is there any possibility to use GWT's built in rpc serialization/deseralization mechanism from client side code? So that I will be able to serialize transfer objects and store them in Local Storage and retrieve them when needed and deserialize the content.

like image 414
AKFA Avatar asked Nov 13 '22 19:11

AKFA


1 Answers

GWT Docs have this to say:

Local Storage is String Storage

HTML5 local storage saves data in string form as key-value pairs. If the data you wish to save is not string data, you are responsible for conversion to and from string when using LocalStorage. For proxy classes used with the GWT RequestFactory, you can use RequestFactory#getSerializer() to do string serializing. For non-proxy objects, you could use JSON stringify and parse.


EDIT:

RequestFactory#getSerializer() returns an implementation of ProxySerializer. But

ProxySerializer Serializes graphs of EntityProxy objects. A ProxySerializer is associated with an instance of a ProxyStore when it is created via RequestFactory.getSerializer(ProxyStore).

So you cannot use it to serialize arbitrary objects. Only EntityProxy objects can be serialized this way. GWT documentation does not mention any method for doing such serialization for non-EntityProxy objects, so I think it is safe to assume that there is no ready-made solution for doing this so far. For non-EntityProxy objects, GWT docs (quoted above) recommend using JSON serialization.

like image 152
Tahir Akhtar Avatar answered Apr 27 '23 18:04

Tahir Akhtar