Sending Generic Parameters (that extend Serializable Interface) in Rpc methods

83 views
Skip to first unread message

Ali Jalal

unread,
Mar 7, 2011, 7:07:54 AM3/7/11
to Google Web Toolkit
Hi,

I see a problem twice in my project. I have these three base
interfaces and class:

public interface BaseModelServiceAsync<M extends BaseModel<IdClass>,
IdClass extends Serializable> {

public void load(IdClass id, AsyncCallback<M> callback);

}

public interface BaseModelService<M extends BaseModel<IdClass>,
IdClass extends Serializable> extends RemoteService {

public M load(IdClass id);
}

public class BaseModelServiceImpl<M extends BaseModel<IdClass>,
IdClass extends Serializable> extends RemoteServiceServlet
implements BaseModelService<M, IdClass> {

public M load(IdClass id) {
M model = ....
return model;
}

}

and I have these three sub-interfaces and sub-class:

public interface AuthorServiceAsync extends
BaseModelServiceAsync<AuthorModel, String> {
}

public interface AuthorService extends BaseModelService<AuthorModel,
String> {
}

public class AuthorServiceImpl extends
BaseModelServiceImpl<AuthorModel, String> implements AuthorService {
}

You can see that IdClass is a Generic parameter that extends
java.io.Serializable and I use this Genetic parameter as first
parameter of load method.

Now, in some ambiguous (!) situations when I call load method for id
'12' in client side, I get this error:
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException:
java.lang.ClassNotFoundException: 12 at
com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:308)
.....
Caused by: com.google.gwt.user.client.rpc.SerializationException:
java.lang.ClassNotFoundException: 12 at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserialize(ServerSerializationStreamReader.java:
567)
at
com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamReader.readObject(AbstractSerializationStreamReader.java:
119)
.....
Caused by: java.lang.ClassNotFoundException: 12

It seems that GWT serialization mechanism "fails" when we use generic
parameters in rpc method's arguments and generic parameters extends an
interface (like java.io.Serializable). In previous errors,
serialization mechanism considers '12' (first argumant of load method)
as Class name of first argument of load method.

Note that this errors will not always occur (for example if we change
'Author' to 'Book' in above sub-interfaces and sub-class, errors will
disappeared (!)).

A simple solution for this problem is that we override load method in
sub-interfaces and sub-class and ignore generic advantages, but it is
not so good.

I want to now that it is some bugs in GWT or it is some mis-usage of
GWT?

With many thanks.
Ali Jalal

Ali Jalal

unread,
Mar 8, 2011, 1:01:10 AM3/8/11
to Google Web Toolkit
I should correct my post:

This problem does not occur accidentally. It occurs when IdClass is
String and does not occur when IdClass is Long.
Reply all
Reply to author
Forward
0 new messages