GWT serialization issue

I have time returning an ArrayList of objects that implement IsSerializable through RPC. IsSerializable pojo contains one variable, String and has a parameter constructor of 0. I deleted the .gwt.rpc file from my war and still get:

com.google.gwt.user.client.rpc.SerializationException: Type 'com.test.myApp.client.model.Test' 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 = com.test.myApp.client.model.Test@17a9692 at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:610) 

I am using GWT 2.0.2 with jdk 1.6.0_18.

Any ideas on what might happen or what am I doing wrong?

Here is the code for the Test class, and the remote method returns an ArrayList. I even modified the code to just return one instance of Test with the same result: the exception is above.

 package com.test.myApp.client.model; import com.google.gwt.user.client.rpc.IsSerializable; public class Test implements IsSerializable{ private String s; public Test() {} public Test(String s) { this.s = s; } public String getS() { return s; } public void setS(String s) { this.s = s; } } 

Thank you for your help! Eddy

+7
serialization gwt
source share
8 answers

This may sound silly, but do you have a default constructor for the test in your code, and not just the version of the code that you posted here? I ran into the same error, searched for it, tried several suggestions here, for example, clean / rebuild, add serialVersionUID, none of them worked. Then I searched more and found a suggestion to make sure that your class you are trying to serialize has a default constructor. Mine did not, and as soon as I added one, it worked. I do not know why this is fixed, but it happened.

+5
source share

I also added an empty constructor to my class, which had a problem, and it worked fine.

+2
source share

The remote method should return an ArrayList<Test> , not just an ArrayList , so GWT understands that Test instances must be serialized.

+1
source share

I use the Serializable interface declaration, so this answer may not apply.

Eclipse always invites me to create a serialVersionUID member for any Serializable class.

 private static final long serialVersionUID = 2388319784164372900L; 

One thought that just hit me, something is not syncing in your assemblies. I suggest you do two things: a) Project | Clean and then b) GWT compilation project.

+1
source share

I also had a problem with ArrayList. I just added an empty constructor and it worked. (My class is already implemented by Serializable)

+1
source share

or its class object cannot be loaded

Is com / test / myApp / client / model / Test.class included in your war?

0
source share

These are the cases that will cause GWT serialization for the error:

1) Your class does not implement Serializable or IsSerializable. 2) There is no default constructor 3) GWT cannot add your class to the whitelist because static code analysis does not show that your class will be included in RPC. In such cases, I create a pair of RPC action / result "WhiteList" (after the command model) and make sure that the action object has members of the corresponding classes that are not working. Sometimes you may find that an object is returned as part of an RPC call in a non-generated collection, and the GWT has no idea to enable it. In this case, it also adds it to the White List action class.

0
source share

I noticed that your class is in the package "com. Test .myApp.client.mode", assuming that it is a "test" class (and should not be part of the expected deployment),

Is your gwt module file (myApp.get.xml) really located in com.test.myApp?

If so, you have chosen the wrong package names. Avoid "testing" in your basic package names - this means that it means that it is a test package.

If not, try moving the class to the "main" package, for example, "com. Mycompany .myApp.client.mode" (if your get module file is in com.mycompany.myApp).

0
source share

All Articles