Serializing JDBC Types in GWT

扶醉桌前 提交于 2019-12-13 19:33:10

问题


I need to serialize object of uknown type(only JDBC types) in GWT. I have an object that holds list of uknown "jdbc" objects and i need it to be transfered from client to server and back. If this object is serializing to file not in gwt client environment I can hold those uknown objects in list of Object's. But GWT can't serialize objects of type Object. How can I achieve this? Any suggestions


回答1:


You may be running into problems if those jdbc types are not being returned by any of your other RPC methods.

If, for instance, your class Foo isn't sent via RPC by any method other than one which returns List[Object], then GWT has no knowledge at compile time (when it generates the RPC whitelist) that Foo is a class that it should generate the code to serialize. This especially makes sense for the generated JavaScript, where avoiding code bloat from unused types is important.

You can work around this by manually adding your otherwise unreferenced classes (all possible return types from JDBC) in a dummy class that gets sent across RPC. How do I add a type to GWT's Serialization Policy whitelist?

Alternately you can write a custom RemoteService generator to use which adds the types without a Dummy class being required. http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html#generator




回答2:


You can return them as

List<Serializable> serviceMethod();

If you guarantee that they are all Serializable. Just cast all of them to Serializable before returning from the service method.




回答3:


See GWT JRE Emulation Reference, there is no Object class and GWT cannot serialize it, so you should create your own transfer object which implements IsSerializable marker interface. Briefly, RPC can not serialize java.lang.Object. Check this links: GWT Sending type OBJECT Via RPC and good thread here: Serialize object and Why is GWT serialization so complicated?



来源:https://stackoverflow.com/questions/9369256/serializing-jdbc-types-in-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!