Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SerializationPolicy error when performing RPC from within GWT application

I'm getting the following exception:

com.google.gwt.user.client.rpc.SerializationException: Type 'java.lang.Long' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized

using GWT 2.1 and the built in Jetty server. According to the docs, this type is definitely serializable... How can I include it in the SerializationPolicy?

like image 439
Tyson Avatar asked Nov 17 '10 09:11

Tyson


4 Answers

Here's the link that should resolve problem: http://developerlife.com/tutorials/?p=131

A user defined class is serializable if:

  1. the class is assignable to IsSerializable or java.io.Serializable, either because it implements one of these interfaces, or because it is derived from a superclass that implements one of these interfaces.
  2. all the class’s non-final, non-transient instance fields are serializable
  3. the class has a public default (zero argument) constructor
like image 154
Krzysztof Uroda Avatar answered Sep 20 '22 22:09

Krzysztof Uroda


Needed include a superfluous method in the RPC service that "whitelists" a number of objects. This arises because of the use of generics, GWT is unable to necessarily determine which object I may be serializing to include within some generic.

I included all of the types that may need to be (un)serialized as members of an object (SerializableWhitelist). I added a method to the RPC servlet object like:

public SerializableWhitelist junk(SerializableWhitelist l) { return null; }

It's worth noting that you need to include the whitelist datatypes as both an argument and as the return type, as GWT apparently maintains two separate serialization policies.

like image 20
Tyson Avatar answered Sep 21 '22 22:09

Tyson


Try deleting the *.gwt.rpc files in your war/app directory, clean and rebuild.

One thing to note: you should avoid long or Long if possible because they are
emulated on GWT (because there is no native Javascript long) and very
slow. Use int instead where ever you can.

like image 32
Peter Knego Avatar answered Sep 20 '22 22:09

Peter Knego


FYI I've raised this as a GWT bug: http://code.google.com/p/google-web-toolkit/issues/detail?id=5811

We'll see what they say.

like image 32
David North Avatar answered Sep 21 '22 22:09

David North