开发者

Strange GWT serialization exception when overiding method of serialized object

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 {
   开发者_JS百科    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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜