是否有可能从客户端代码中使用GWT内置的rpc序列化/解除机制?这样我就可以序列化传输对象并将它们存储在本地存储中,并在需要时检索它们并反序列化内容.
GWT Docs有这个说: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.
编辑:
RequestFactory#getSerializer()
返回ProxySerializer
的实现.但是
ProxySerializer Serializes graphs of EntityProxy objects. A
ProxySerializer is associated with an instance of a ProxyStore when it
is created via RequestFactory.getSerializer(ProxyStore).
所以你不能用它来序列化任意对象.只有EntityProxy对象可以通过这种方式序列化. GWT文档没有提到为非EntityProxy对象进行此类序列化的任何方法,因此我认为可以安全地假设到目前为止还没有现成的解决方案.对于非EntityProxy对象,GWT文档(上面引用)建议使用JSON序列化.