GWT序列化问题 [英] GWT serialization issue

查看:205
本文介绍了GWT序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段时间返回一个通过RPC实现IsSerializable的对象的ArrayList。 IsSerializable pojo包含一个变量,一个String,并且有一个0参数构造函数。我已经从我的战争中删除了.gwt.rpc文件,但仍然得到:

  com.google.gwt.user.client .rpc.SerializationException:类型'com.test.myApp.client.model.Test'未包含在可由此SerializationPolicy序列化的类型集合中,或者其Class对象无法加载。为了安全起见,这种类型不会被序列化:实例= com.test.myApp.client.model.Test@17a9692 
在com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize( ServerSerializationStreamWriter.java:610)

我使用GWT 2.0.2和jdk 1.6.0_18。 p>

关于可能发生什么或我做错什么的想法?

以下是测试代码类和远程方法正在返回ArrayList。我甚至修改了它的代码,只是返回一个具有相同结果的Test实例:上面的异常。

  package com.test.myApp.client.model; 

import com.google.gwt.user.client.rpc.IsSerializable;

public class Test实现了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;
}
}

非常感谢帮助! Eddy

解决方案

这可能听起来很愚蠢,但是您在代码中是否具有Test的默认构造函数,而不仅仅是版本你在这里发布的代码?我遇到了同样的错误,搜索了一下,尝试了几个建议,比如clean / rebuild,添加serialVersionUID,没有任何工作。然后,我搜索了更多,并找到了一个建议,以确保您尝试序列化的类具有默认构造函数。我没有,只要我加了一个,它就起作用了。我不知道为什么解决这个问题,但确实如此。


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

解决方案

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.

这篇关于GWT序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆