GWT - RPC SerializationException

假如想象 提交于 2019-11-27 20:42:24

This is normally caused by using a non-serializable class, which can occur if your class does not implement com.google.gwt.user.client.rpc.IsSerializable or if you have forgotten to add an empty constructor.

To pass a bean you have to fulfill the following requirements (from GWT site):

  1. It implements either Java Serializable or GWT IsSerializable interface, either directly, or because it derives from a superclass that does.
  2. Its non-final, non-transient instance fields are themselves serializable
  3. It has a default (zero argument) constructor with any access modifier (e.g. private Foo(){} will work)

Even if you fulfill these requirements may happen that GWT compiler say:

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.: instance = @

The problem may have different causes. Here his a complete check list to use for solving the problem:

  1. Verify that the class has a default constructor (without arguments)
  2. Verify that the class implements Serializable or IsSerializable or implements an Interface that extends Serializable or extends a class that implement Serializable
  3. Verify that the class is in a client.* package or …
  4. Verify, if the class is not in client.* package, that is compiled in your GWT xml module definition. By default is present. If your class is in another package you have to add it to source. For example if your class is under domain.* you should add it to xml as . Be aware that the class cannot belong to server package! More details on GWT page: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModuleXml
  5. If you are including the class from another GWT project you have to add the inherits to your xml module definition. For example if your class Foo is in the package com.dummy.domain you have to add to the module definition. More details here: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideInheritingModules
  6. If you are including the class from another GWT project released as a jar verify that the jar contains also the source code because GWT recompile also the Java source for the classes passed to the Client.

PS:copied from http://isolasoftware.it/2011/03/22/gwt-serialization-policy-error/ because the site is unavailable currently. If you want to read the original article search it from google using the above URL and read it from google web cache.

Ahother reason for this exeption was outdated javascript on browser side. I had to hard reload (CTRL+F5) the code and this exception was gone.

I get also this error when I used sublist:

return myList.subList(fromIndex, toIndex);

In my case there is some old cache in my target folder that wasn't properly updated. I had to rebuild the project (Maven -> Update Project) and then it worked.

First of all, be sure to have defined an empty constructor.
If not, your class will not be serializable ...

If you have an empty constructor, be sure that your class (or any class in the extends chain) implements IsSerializable (or any other interface which extends IsSerialisable)

If your class implements IsSerialisable, check it is non-final ...

As mentioned by Cipous, in my case I had this exception thrown in the server output in Pentaho BI Server. A simple hard reload (CTRL+F5) did the trick.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!