Has any one written new annotations for GWT Client side ?

1,291 views
Skip to first unread message

keyboard_samurai

unread,
Dec 3, 2009, 10:21:29 PM12/3/09
to Google Web Toolkit, yoges...@mphasis.com
Hi,

I am a newbie to GWT. Need to know if GWT can support custom
annotations on client side ?. The reason for custom annotations is i
would be communicating with the backend service through json and not
gwt rpc and i wouldnt like each developer to write the same piece of
code. So i was planning to annotated my entity classes which can be
used for marshalling and unmarshalling json response.

Please do let me know if this can be done in GWT.

Thanks in advance

cheers!

Jamie Gennis

unread,
Dec 4, 2009, 11:43:00 AM12/4/09
to google-we...@googlegroups.com
Annotations in client code can be used during GWT's rebind phase of the compilation, but they are not accessible at runtime on the client side.  GWT doesn't support much of Java's reflection functionality on the client side in order to keep the compiled Javascript code smaller.

You can write a custom generator, which can be called to create implementation code for specific interfaces during the rebind phase, to generate your marshaling code at compile-time.  This is the approach taken by lovely-gwt-jsonrpc, for example, and is how all of GWT's built-in RPC functionality works.  You may be able to leverage some or all of the work in that project to accomplish what you're trying to do.

Jamie


--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



keyboard_samurai

unread,
Dec 5, 2009, 10:10:15 AM12/5/09
to Google Web Toolkit
Thanks for the reply ...

Can you provide more information on the generator side and how can i
accomplish this ?

I would definitely look into the lovely json rpc code. Any directions
on this would be greatly appreciated.

Thank you !

Cheers!

On Dec 4, 9:43 pm, Jamie Gennis <jgen...@gmail.com> wrote:
> Annotations in client code can be used during GWT's rebind phase of the
> compilation, but they are not accessible at runtime on the client side.  GWT
> doesn't support much of Java's reflection functionality on the client side
> in order to keep the compiled Javascript code smaller.
>
> You can write a custom generator, which can be called to create
> implementation code for specific interfaces during the rebind phase, to
> generate your marshaling code at compile-time.  This is the approach taken
> by lovely-gwt-jsonrpc <http://code.google.com/p/lovely-gwt-jsonrpc/>, for
> example, and is how all of GWT's built-in RPC functionality works.  You may
> be able to leverage some or all of the work in that project to accomplish
> what you're trying to do.
>
> Jamie
>
>
>
> On Thu, Dec 3, 2009 at 7:21 PM, keyboard_samurai <yog...@gmail.com> wrote:
> > Hi,
>
> > I am a newbie to GWT. Need to know if GWT can support custom
> > annotations on client side ?. The reason for custom annotations is i
> > would be communicating with the backend service through json and not
> > gwt rpc and i wouldnt like each developer to write the same piece of
> > code. So i was planning to annotated my entity classes which can be
> > used for marshalling and unmarshalling json response.
>
> > Please do let me know if this can be done in GWT.
>
> > Thanks in advance
>
> > cheers!
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsubs cr...@googlegroups.com>
> > .

Jamie Gennis

unread,
Dec 5, 2009, 2:20:45 PM12/5/09
to google-we...@googlegroups.com
> Can you provide more information on the generator side and how can i
> accomplish this ?

It's not really well documented as far as I know, so the best place to get information is by reading the source code of GWT and other libraries that implement generators.  The basic idea is that in your .gwt.xml file you specify an interface and a Generator class.  When the GWT compiler comes across a GWT.create(Foo.class) call where Foo.class extends the interface you specified, it calls your Generator class to create the implementation of that interface.  Your Generator class can then generate the Java code for the implementation of the interface, and an instance of that generated class will be returned by the GWT.create() call.

This is how GWT's RPC interfaces work (see RemoteService.gwt.xml and ServiceInterfaceProxyGenerator) as well as many other GWT features (localization, UI binder, client bundles).  You can also define a class that gets invoked at the GWT compiler's link phase, but I don't think you'd need to do this just for JSON marshaling.

Jamie

To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages