gwt中的序列化问题 [英] serialization problem in gwt

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

问题描述

我已阅读:

GWT序列化问题

但是没有解决办法.

我的包裹是:

软件包gwt.web 包gwt.web.client; 等等...

package gwt.web package gwt.web.client; etc...

我有软件包模型

我的班级'models.Word'所在的位置

Where is located my class 'models.Word'

如您所见,此类不在int gwt.cleint中,但不应位于该类中,它不是客户端类.

As you can see this class is located not int gwt.cleint, but it should not be there, it is not client side class.

此类具有默认构造函数,因此这不是问题.

this class has default constructor, so this is not issue.

我有例外:

服务方法'公共抽象java.util.List gwt.web.client.WordService.getWords(java.lang.String)'引发了 意外的异常: com.google.gwt.user.client.rpc.SerializationException:类型 "models.Word"未包含在可以设置为 无法通过此SerializationPolicy或其类对象序列化 被加载.为了安全起见,将不对此类型进行序列化. 实例= Word [null]

Service method 'public abstract java.util.List gwt.web.client.WordService.getWords(java.lang.String)' threw an unexpected exception: com.google.gwt.user.client.rpc.SerializationException: Type 'models.Word' 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 = Word[null]

在我的App.gwt.xml中:

in my App.gwt.xml:

<!-- Specify the paths for translatable code                    -->
<source path='models'/>

所以这对我上课很客气.因此,这也不应该是问题.

so this poits to my class. so, it should not be the issue as well.

问题:如何处理?我需要使用我的模型类通过Services通过ajax传递它.

The question: how to handle that? I need use my models classes to pass its by ajax by Services.

我的班级是可序列化的(该接口的实现).

My Class is serializable (implements that interface).

此类是我的代码的一部分. RPC中使用的此类:

This class is part of my code. This class used in RPC:

@RemoteServiceRelativePath("wordServiceImpl")
public interface WordService extends RemoteService {
    public List<Word> getWords(String langCode);
}

推荐答案

要记住的一件事是GWT会优化,并且在不需要时不会序列化所有类.

One key thing to keep in mind is that GWT optimizes and does not serialize all classes if not required.

如果您的类不属于任何RPC调用的一部分(即RPC调用中使用的类没有将该类对象作为数据成员),则GWT不会序列化该类,因为它假定不需要该类.

If your class is not part of any RPC call (i.e. classes used in RPC call don't have this class object as a data member), GWT would not serialize this class as it assumes its not needed.

您的代码是否属于这种情况?在这种情况下,只需将此类的虚假数据成员添加到RPC中使用的类中即可

Is this the case with your code? In that case, just add a fake data member of this class to a class used in RPC

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

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