Dmitriy Sukharev
Dmitriy Sukharev

Reputation: 1124

JSON service in GWT

I'm working with SmartGWT / ExtGWT and want to know about implementation of JSON communication between server and client in these frameworks.

In my case data is stored on server side in session. If there is no data in session, server reads it from the specified XML and saves to session. Fetch: client requests data from server in JSON format, server reads data from session and sends it to client in JSON. Update: client sends information about update to server in JSON format, server parses it and updates session. Actually I need only implement communication between UI components and server via JSON.

What I do not understand is how it's possible to implement such communication between server and client. I know that client's UI components in SmartGWT and ExtGWT can work with JSON, but have for this quite specific format. But I have no idea how to implement such JSON service on the server side. I think that there are should be some approaches in ExtGWT / SmartGWT, but I couldn't find them. The only way I see is implementing servlet(s) which will generate dynamical JSON responses, and will parse JSON requests. But I think that it's not very good idea. (Honestly I hope that there's the way that is such trivial as RPC service.) Also I hope that there is easier way than implement my own REST service. Now I'm reading about AutoBean, but as far as I understand I can use it only for translation to and from JSON format, not for implementation of service.

Please tell me, what is the best way to implement such JSON service in SmartGWT or ExtGWT.

UPD: I want to emphasise that I need communication between server and UI components. REST or some other services are not required. Therefore I hope that ExtGWT and SmartGWT provides some tools for this (I found tools from client side, but nothing from server side). I would appreciate if you tell me what that tools are, or that there're no such tools.

Upvotes: 1

Views: 733

Answers (1)

Riley Lark
Riley Lark

Reputation: 20890

I use RESTEasy to quickly marshal/unmarshal json into/from java objects on the server. Works like a charm. You could also look at the GSON library, which gives you a little more control/responsibility.

The basic structure is indeed to register a servlet that handles JSON communication for you. RESTEasy comes with a default servlet that you can install which has fancy/convenient routing annotations. I think RESTEasy can also handle XML for no extra fee, which would be nice in the case of third-party clients, but I haven't used that feature.

Upvotes: 1

Related Questions