21

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?

Tyson
  • 968
  • 1
  • 6
  • 15
  • Could you please show us the remote interface causing the exception? – z00bs Nov 17 '10 at 09:25
  • Or see here: http://groups.google.com/group/google-appengine-java/browse_thread/thread/6b9a620025e65ad2 – z00bs Nov 17 '10 at 09:38
  • yeah, i've just tried everything. cleaning, rebuilding, dummy methods that explicitly reference the needed types, and it's still happening. it's happening with lots of different types, in fact. Date, Integer, and more. the original problem arose after using only generics (Map). – Tyson Nov 17 '10 at 09:56

10 Answers10

28

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
Igor Klimer
  • 15,321
  • 3
  • 47
  • 57
Krzysztof Uroda
  • 281
  • 3
  • 2
20

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.

Tyson
  • 968
  • 1
  • 6
  • 15
  • 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. – Stroboskop May 20 '11 at 12:49
  • Thank you a lot; without your answer I'll have been trying to fix that stuff for hours :) – Guillaume Nov 23 '11 at 10:58
8

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.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • 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... – broc.seib Oct 02 '11 at 20:22
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.

David North
  • 1,247
  • 1
  • 14
  • 32
  • David, how do you normally get around this issue? – Snekse Jun 07 '11 at 23:00
  • 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. – David North Jun 08 '11 at 15:58
3

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 {...
Peter L
  • 2,921
  • 1
  • 29
  • 31
1

The problem can also be because the code on your local machine on which you are running hosted mode is not the same as the one on the external server you are connecting to via RPC. So in my case i was missing a git pull on my local machine to match what was deployed on the external server. The changes were minimal, just a new property in one of the classes that were included in the gwt.rpc, but this was already sufficient that the gwt.rpc md5 filenames were different and thus the above mentioned error occurred.

Dominik Steiner
  • 141
  • 1
  • 4
0

Another FWIW: I believe I cleared up a similar problem in an enum class by changing the access modifier of the single, one argument constructor from default (no modifier) to 'private'. In any event, doing that didn't break it because it's working that way now.

Mark Villa
  • 11
  • 2
0

I faced this error and got stuck for 1 day completely. Then I came to across following quick solution:

Make sure your DTOs or Entities classes following the serializable interface rules. Its the the only thing you need to do because rest of the issues will be with your build creation. So if you are using maven then make sure do clean build and clear all browser cache. I resolved my issues with this. I hope it will help. Thanks!

Aman Goel
  • 3,351
  • 1
  • 21
  • 17
0

Make sure that the class is in shared folder. This is what I was Missing.

Mini Agarwal
  • 21
  • 1
  • 1
  • 8
0

Inspired by http://groups.google.com/group/google-web-toolkit/browse_thread/thread/7dd5123d359ddfa8

Using eclipse and maven and gwt 2.1.1

Compile and deploy gwt war.

Try using OOPHM launched from Eclipse.

This would fail for me.

This will generate in server logs:

ERROR: The serialization policy file 'blah.gwt.rpc' was not found; did you forget to include it in this deployment?

WARNING: Failed to get the SerializationPolicy '94DEC228B2828D3A5897FEE3D6845A40' for module 'http://blah:8080/BlahUI/BlahUI/'; a legacy, 1.3.3 compatible, serialization policy will be used. You may experience SerializationExceptions as a result.

And then

Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type '[LpathToClass;' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.For security purposes, this type will not be serialized.: instance = [LpathToClass;@9d524af at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)

Now that extra gwt.rpc files have been generated (either by eclipse/maven plugin who knows?)

Recompile (even a clean compile will work because the gwt.rpc files are not in the target folder, my OOPHM gwt.rpc files are at same folder as entrypoint html) and redeploy. This new war file will contain the generated gwt.rpc files.

Relaunch OOPHM from Eclipse.

Works for me.

Thomas Newman
  • 164
  • 1
  • 6