SerializationPolicy error when performing RPC from within GWT application

20,774

Solution 1

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.

Solution 2

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

Solution 3

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.

Solution 4

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.

Solution 5

FWIW, I was having this problem but my 'Object' type was hidden behind generified classes. The error message itself was wrong.

So if one of your rpc methods involves a class:

class Xxx<T> implements IsSerializable {...

It needs to change to:

class Xxx<T extends IsSerializable> implements IsSerializable {...
Share:
20,774
Tyson
Author by

Tyson

Updated on July 07, 2020

Comments

  • Tyson
    Tyson almost 4 years

    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?

  • Stroboskop
    Stroboskop almost 13 years
    Thank you so much. I have been looking for a solution to that design problem for a week now. And even though it's a workaround - explicitly defining a whitelist seems to be a good idea.
  • Snekse
    Snekse almost 13 years
    David, how do you normally get around this issue?
  • David North
    David North almost 13 years
    As described on the bug / the above comment - either get rid of the generics (e.g. by using an array instead of a collection) or by including a spurious RPC method which directly references the types causing the problem. Disappointingly, Google haven't indicated any progress on the bug in six months, though I haven't had a chance to try this in newer versions of GWT than my ancient 1.7.
  • broc.seib
    broc.seib over 12 years
    Deleting the *.gwt.rpc files from my war/myapp directory is what fixed this problem for me. (In fact, I just nuked everything in my war/myapp directory.) I didn't need any dummy calls since my class was already being passed to/from in other RPC calls. And I had a default constructor. Another thing to watch for: be sure you use "?gwt.codesvr=127.0.0.1:9997" in your URL...
  • Guillaume
    Guillaume over 12 years
    Thank you a lot; without your answer I'll have been trying to fix that stuff for hours :)
  • Igor Kupczyński
    Igor Kupczyński over 12 years
    Right, this is what they are asking for
  • GameBuilder
    GameBuilder almost 12 years
    Thanks alot, without this this i could not have solve my problem.
  • nikhil
    nikhil about 11 years
    After I did all of that I didn't reload my browser window and kept getting the error. This helped me comments.gmane.org/gmane.org.google.gwt/76401