GWT JSON library with JAXB class reuse?

48 views
Skip to first unread message

Gabor Szokoli

unread,
Dec 12, 2008, 8:51:07 AM12/12/08
to Google-We...@googlegroups.com
Hi there!

I'm new to GWT and think it's great. Please keep in mind the below is
intended in a far more humble and grateful tone than I can represent
in English:

We're doing a pilot with GWT, hoping to create a "static" (client
only) application that uses an existing REST-like JSON service
implemented with Jersey.
The initial implementation uses RequestBuilder, eval, and a dumb overlay type.
JSONParser would be an alternative, producing JSONArray.

What I'd prefer instead is reuse of my existing (JAXB annotated) Java
class from the server side in GWT client code.

This is of course not an issue in the pilot project itself, but will
get uncomfortable in larger projects.
It also negates what we expected to be one of the main advantages of
implementing the web service and the client application in the same
language: code reuse.

Does any of the existing GWT JSON libraries support this?
This is the closest I have found, but it looks abandoned:
http://code.google.com/p/gwt-jsonizer/

Or is there a more server-side friendly alternative to
JavaScriptObject for overlay types? (JAXB and JPA frown upon the
protected constructor)
I guess not, so can we have one? :-)
I assume a lot of thought went into the current overlay type design,
but server side code reuse does not seem to have been a design goal,
and might require an alternative binding method.


Any advice appreciated:

Gabor Szokoli

Shawn Pearce

unread,
Dec 12, 2008, 3:08:20 PM12/12/08
to Google-We...@googlegroups.com
You might want to look at my still-under-development gwtjsonrpc:

  http://android.git.kernel.org/?p=tools/gwtjsonrpc.git;a=blob;f=README;hb=HEAD

I think it mostly does what you are looking for, but it doesn't pay any attention to JAXB annotations.  Its mostly complete for my application's needs, but I haven't put it into production yet.

Gabor Szokoli

unread,
Dec 12, 2008, 8:19:51 PM12/12/08
to Google-We...@googlegroups.com
On Fri, Dec 12, 2008 at 9:08 PM, Shawn Pearce <s...@google.com> wrote:
> You might want to look at my still-under-development gwtjsonrpc:
>
>
> http://android.git.kernel.org/?p=tools/gwtjsonrpc.git;a=blob;f=README;hb=HEAD

Wow.
Looks impressive!
Thank you!

> I think it mostly does what you are looking for,

It does a lot more (I'd prefer to leave the server side to Jersey and
I'll make a RESTful service instead of RPC), but from what I
understand, your RemoteJsonServiceProxyGenerator seems to do what I
want.

Let me learn about GWT generators before I can comprehend it :-)

> but it doesn't pay any
> attention to JAXB annotations.

That's probably OK for me, my entities are quite simple, mapped
without extra annotations. I might have to add support for the
@XmlTransient later at most.

Sounds like a good general purpose project for bored GWT pros though:
"JSO generator from JAXB for JSON"

(Or am I trying to do something unreasonable here? I mean how come I'm
the first to complain about this?)


Gabor Szokoli

Ps: Generators... This new learning amazes me. Next thing we know GWT
will be employed to prevent earthquakes.

Shawn Pearce

unread,
Dec 12, 2008, 8:41:46 PM12/12/08
to Google-We...@googlegroups.com
On Fri, Dec 12, 2008 at 17:19, Gabor Szokoli <szo...@gmail.com> wrote:

On Fri, Dec 12, 2008 at 9:08 PM, Shawn Pearce <s...@google.com> wrote:
> You might want to look at my still-under-development gwtjsonrpc:
>
> http://android.git.kernel.org/?p=tools/gwtjsonrpc.git;a=blob;f=README;hb=HEAD
> I think it mostly does what you are looking for,

It does a lot more (I'd prefer to leave the server side to Jersey and
I'll make a RESTful service instead of RPC), but from what I
understand, your RemoteJsonServiceProxyGenerator seems to do what I
want.

Right.  My reason for offering it as an example was you can use the client by itself, without touching the server at all.  Its meant to permit implementation of the GWT server side in any system that has the ability to create JSON text, which is anything that can create text.  :)

You just need to have the Java objects the client side is using have property names which match up with the property names appearing in the JSON data - but that's probably exactly what you would want to do if you were interfacing with an existing JSON service, or were developing one from scratch.

Let me learn about GWT generators before I can comprehend it :-)

You shouldn't need to know alot to use it.  Run "make", copy gwtjsonrpc.jar into your CLASSPATH and inherit the module.  GWT's compiler automatically calls RemoteJsonProxyGenerator when you declare an interface extending RemoteJsonService and create an instance of it with GWT.create().
Reply all
Reply to author
Forward
0 new messages