Hi all, thanks for your comments and advices.
To solve my problem I'll do something like Didier said : I'll
instantiate an object of type T (which is Serializable), instead of
Class<T>, and pass it to the server via the RPC.
class MyType<T extends MyGen> implements Serializable {
T anObject;
MyType() {} // mandatory no-arg contructor
MyType(T anObject) { // with a non-null param value !
this.anObject = anObject;
}
}
Doing so, the server will receive a MyType object, will recognize the
type T of anObject and will be able to select the right handler.
And even the generics is not anymore required as the type of anObject
will be checked dynamically by the server.
Actually class.getCanonicalName() is not implemented too in GWT, so my
previous post is not realistic.
I personnaly prefer this solution than harcode the full className (as
it will change if I reorganize the packages...)
Regards
Yves
On 14 déc, 15:51, ep <[email protected]> wrote:
> you dont need to, just put a fullyqualified classname on the wire and
> forName() it in the VM. you may also think about providing your custom
> field serializer for the class, but actually would be nonsense since
> you anyway cannot use it reasonably on the client
>
> On 14 Dez., 12:20, yves <[email protected]> wrote:
>
> > @Didier
> > Of course MyType implements Serializable . It is just a typo in the
> > example. Sorry.
>
> > @Paul
> > I didn't realized that Class is not GWT-serializable. Thanks for your
> > remark. I lost pretty much time to find out why I get an exception
> > during an RPC call
>
> > It would have been nice if Class<T> was serializable. I would have
> > used it to select an appropriate handler at server-side. Anyway I use
> > instead the canonical class name to map the handler, but the code is
> > little bit more uggly :-)
>
> > I noticed also the a call to class.hashCode() does not give the same
> > value in the (gwt-compiled)-client and in the (JVM running)-server.
> > In my attempts to workaround the "unserializability" of Class, I tried
> > to use the hashCode() value, unsuccessfully...
>
> > Regards
> > Yves
>
> > On 14 déc, 10:42, Paul Robinson <[email protected]> wrote:
>
> > > Class is not gwt-serializable.
>
> > > MyType has a non-final, non-transient field of type Class
>
> > > Therefore MyType is not serializable
>
> > > On 14/12/10 09:33, Didier Durand wrote:
>
> > > > Hi,
>
> > > > Serializable is an interface not a class. That's why it's not the list
> > > > you mention. An interface has nothing to be serialized per se.
>
> > > > You should let us know about your class MyType in order to better
> > > > help.
>
> > > > regards
>
> > > > didier
>
> > > > On Dec 14, 9:21 am, Paul Robinson<[email protected]> wrote:
>
> > > >> If you look at the Class.java that GWT uses to emulate the JVM's Class,
> > > >> you'll see that it does not implement Serializable.
>
> > > >> On 13/12/10 22:19, yves wrote:
>
> > > >>> Hi,
>
> > > >>> I have a class defined in a way similar to this:
>
> > > >>> class MyType<T extends MyGen> extends Serializable {
>
> > > >>> private Class<T> aClass;
>
> > > >>> public MyType() {}
>
> > > >>> public void setClass(Class<T> aClass) {
> > > >>> this.aClass = aClass;
> > > >>> }
> > > >>> }
>
> > > >>> where MyGen is also Serializable
>
> > > >>> When I compile de project (I'am currently still using GWT 2.1.0 RC1),
> > > >>> then I find the following :
>
> > > >>> 1) the compiler (using the compiler options -extra, -work and -gen)
> > > >>> does not generate the code MyType_FieldSerializer.java as it does for
> > > >>> all other serializable classes.
>
> > > >>> 2) In the "extra" / rpclog dir, the class MyType is flagged like this:
> > > >>> Serialization status
> > > >>> Not serializable
>
> > > >>> 3) And when I run my app, I get an "InvocationException" : the client
> > > >>> is unable to make an RPC call with a parameter of type MyType.
>
> > > >>> Is it a bug in the compiler, or did I missed something about Class<T>
> > > >>> "serializability" ?
>
> > > >>> Thanks for your help
> > > >>> Yves
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.