1

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

maks
  • 5,911
  • 17
  • 79
  • 123
  • Are they all actually GWT serializable? Are these classes created by you? – Strelok Feb 21 '12 at 05:52
  • Classes created by me are Serializable, and also JDBC types(java types that represent Database types) are also Serializable(see http://db.apache.org/ojb/docu/guides/jdbc-types.html), maybe except Blob and Clob, but I don't work with them – maks Feb 21 '12 at 09:56

3 Answers3

4

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

Community
  • 1
  • 1
idle
  • 1,117
  • 9
  • 17
  • Even if I write such Dummy class, can I use `List serviceMethod()` to return that types in this list? – maks Feb 21 '12 at 18:28
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.

Strelok
  • 50,229
  • 9
  • 102
  • 115
0

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?

Community
  • 1
  • 1
Jama A.
  • 15,680
  • 10
  • 55
  • 88
  • I know that Object class is not serialized by GWT. That is a goal of my question to get know how can I serialze uknown object that have common supertype as Object – maks Feb 21 '12 at 09:53
  • No GWT-RPC cannot serialize java.lang.Object, besides that List, Map also cannot be serialized – Jama A. Feb 21 '12 at 10:19