覆盖序列化对象的方法时出现奇怪的 GWT 序列化异常
我有一个 GWT 可序列化类,我们称之为 Foo。 Foo 实现 IsSerialized,具有原始成员和可序列化成员以及其他瞬态成员和无参数构造函数。
class Foo implements IsSerializable {
// transient members
// primitive members
public Foo() {}
public void bar() {}
}
也是一个在 RPC 通信中使用 Foo 实例的服务。
// server code
public interface MyServiceImpl {
public void doStuff(Foo foo);
}
public interface MyServiceAsync {
void doStuff(Foo foo, AsyncCallback<Void> async);
}
我如何使用它:
private MyServiceAsync myService = GWT.create(MyService.class);
Foo foo = new Foo();
...
AsyncCallback callback = new new AsyncCallback {...};
myService.doStuff(foo, callback);
在上面的情况下,代码正在运行,并且回调实例的 onSuccess() 方法被执行。
但是,当我像这样重写 foo 实例上的 bar() 方法时:
Foo foo = new Foo() {
public void bar() {
//do smthng different
}
};
AsyncCallback callback = new new AsyncCallback {...};
myService.doStuff(foo, callback);
我收到 GWT SerializationException。
请赐教,因为我实在不明白为什么。
I have a GWT serializable class, lets call it Foo.
Foo implements IsSerializable, has primitive and serializable members as well as other transient members and a no-arg constructor.
class Foo implements IsSerializable {
// transient members
// primitive members
public Foo() {}
public void bar() {}
}
Also a Service which uses Foo instance in RPC comunication.
// server code
public interface MyServiceImpl {
public void doStuff(Foo foo);
}
public interface MyServiceAsync {
void doStuff(Foo foo, AsyncCallback<Void> async);
}
How i use this:
private MyServiceAsync myService = GWT.create(MyService.class);
Foo foo = new Foo();
...
AsyncCallback callback = new new AsyncCallback {...};
myService.doStuff(foo, callback);
In the above case the code is running, and the onSuccess() method of callback instance gets executed.
But when I override the bar() method on foo instance like this:
Foo foo = new Foo() {
public void bar() {
//do smthng different
}
};
AsyncCallback callback = new new AsyncCallback {...};
myService.doStuff(foo, callback);
I get the GWT SerializationException.
Please enlighten me, because I really don't understand why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题来自 rpc 序列化策略,该策略为 rpc 服务创建可序列化类型的“白名单”。
在您的情况下,“Foo”类位于白名单中,但是当您重写方法时,您创建了一个扩展 Foo 但不在白名单中的匿名类,因此 GWT 拒绝序列化它......我看不出有什么办法你想要什么而不创建显式子类......
I think the problem comes from the rpc serialization policy which creates a "white list" of serializable types for the rpc service.
In your case the "Foo" class is in the whitelist but when you override a method, you create an anonymous class that extends Foo but is not in the whitelist, so GWT refuses to serialize it... and I see no way to do what you want without creating an explicit subclass...