GWT - RPC SerializationException

前端 未结 6 1801
感情败类
感情败类 2020-12-05 15:38

It\'s been a while since I\'ve been doing GWT and I needed something small done quickly. I set things up and now I have a RPC I need, but it fails.

The RPC is suppos

相关标签:
6条回答
  • 2020-12-05 15:48

    I get also this error when I used sublist:

    return myList.subList(fromIndex, toIndex);
    
    0 讨论(0)
  • 2020-12-05 15:53

    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.

    0 讨论(0)
  • 2020-12-05 15:56

    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.

    0 讨论(0)
  • 2020-12-05 16:00

    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.

    0 讨论(0)
  • 2020-12-05 16:01

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

    0 讨论(0)
  • 2020-12-05 16:08

    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.

    0 讨论(0)
提交回复
热议问题