views:

207

answers:

8

I am having a heck of a time returning an ArrayList of objects that implement IsSerializable via RPC. The IsSerializable pojo contains one variable, a String, and has a 0 parameter constructor. I have removed the .gwt.rpc file from my war and still I 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 be going on or what I am doing wrong?

Here is the code for the Test class and the remote method is returning ArrayList. I even modified the code for it to just return one instance of Test with the same result: the exception 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;
    }
}

Greatly appreciate the help! Eddy

A: 

The remote method needs to return ArrayList<Test>, not just ArrayList, so that GWT understands that instances of Test will need to be serialised.

tdavies
The remote method is returning ArrayList<Test>. Like I said, I even tried returning one instance of Test with the same result.
Eddy
A: 

I'm used to using the Serializable interface declaration so this answer may not apply.

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

private static final long serialVersionUID = 2388319784164372900L;

One thought that just hit me, something is out of sync in your builds. I suggest you do two things: a) Project | Clean, and then b) GWT Compile Project.

Stevko
I tried using Serializable with a generated serialVersionUID but that didn't work either. Thanks though! Any other ideas?
Eddy
I have tried both a and b .. numerous times actually.
Eddy
I just ran into this error message last night. I deployed (several times) a slightly modified rather large project but did not increment the version number and kept getting the serialization exception on a older class. Finally incremented the version number and redeployed - it cleared up. Is your Test class even being translated into JavaScript?Check the path included in a myApp.gwt.xml <source path=... /> tag. The comment states "Speicfy the paths for translatable code".
Stevko
A: 

or its Class object could not be loaded

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

Isaac Truett
A: 

Hi, Eddy! Did you find any solution? I've spent quite a lot of time with same issue and still can't find any answers. I'll be very grateful for your help.

Yury Khrol
+1  A: 

This may sound silly, but do you have a default constructor for Test in your code, and not just on the version of the code you posted here? I encountered this same error, googled it, tried several of the suggestions here like clean/rebuild, add serialVersionUID, none of it worked. Then I searched more and found a suggestion to make sure your class that you're trying to serialize has a default constructor. Mine didn't, and as soon as I added one, it worked. I don't know why that fixed it, but it did.

that's because GWT serialization is not Java serialization... explained in the FAQ : http://code.google.com/intl/fr/webtoolkit/doc/1.6/FAQ_Server.html#Does_the_GWT_RPC_system_support_the_use_of_java.io.Serializable
Vinze
A: 

I also added an empty constructor to my class that was having the problem, and it worked fine.

A: 

These are the cases that will cause GWT serialization to throw an error:

1) Your class does not implement Serializable or IsSerializable. 2) No default constructor 3) GWT is unable to add your class to the "whitelist" because a static analysis of the code does not show that your class will be included in RPC. For such cases, I create a "WhiteList" action/result RPC pair (following the command model) and ensure that the action object has members of the relevant classes that are failing. Sometimes you may find that an object is returned as part of an RPC call in a non-generified collection and GWT has no clue to include it. In this case also, adding it to the "WhiteList" action class helps.

kabram
A: 

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

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

If so, you have chosen your package names poorly. Avoid putting "test" in your main package names - convention dictates this means it's a test package.

If not, try moving your class to a "main" package, eg "com.mycompany.myApp.client.mode" (assuming your get module file is in com.mycompany.myApp).

Bohemian