SerializationPolicy error when performing RPC from within GWT application
Asked Answered
D

10

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?

Discomfort answered 17/11, 2010 at 9:16 Comment(3)
Could you please show us the remote interface causing the exception?Indianapolis
Or see here: groups.google.com/group/google-appengine-java/browse_thread/…Indianapolis
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).Discomfort
D
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.

Discomfort answered 20/11, 2010 at 22:19 Comment(2)
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.Antlion
Thank you a lot; without your answer I'll have been trying to fix that stuff for hours :)Guria
A
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
Alluvial answered 11/9, 2011 at 18:16 Comment(3)
Right, this is what they are asking forSchlesinger
Thanks alot, without this this i could not have solve my problem.Datary
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/76401Vibrant
D
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.

Discomfort answered 20/11, 2010 at 22:19 Comment(2)
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.Antlion
Thank you a lot; without your answer I'll have been trying to fix that stuff for hours :)Guria
M
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.

Mazarin answered 17/11, 2010 at 9:34 Comment(1)
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...Firstly
A
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.

According answered 23/12, 2010 at 15:9 Comment(2)
David, how do you normally get around this issue?Ninfaningal
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.According
A
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 {...
Adamec answered 22/5, 2013 at 5:15 Comment(0)
Z
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.

Zitazitah answered 24/1, 2012 at 15:44 Comment(0)
U
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.

Upcoming answered 26/10, 2011 at 3:58 Comment(0)
I
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.

Important answered 11/6, 2013 at 0:1 Comment(0)
B
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!

Babbitt answered 27/3, 2017 at 12:25 Comment(0)
H
0

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

Hobgoblin answered 6/7, 2017 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.