开发者

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开发者_StackOverflow 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?


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


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.


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.


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.


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 {...


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.


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.


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.


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜