The easiest way by far is to use RestyGWT
http://restygwt.fusesource.org/documentation/index.html
With it, you just create GWT RPC style service interfaces to access
restful JSON resources.
For example, lets say you want to post some JSON to a URL of "/blog/
comments":
{
"author":"Hiram",
"website":"http://hiramchirino.com",
"comment":"This is my comment."
}
and you expect to get some JSON back that looks like:
{
"comment-id":1234,
"moderated":true
}
The you would create some DTO style classes to give you type safe
access to the request and response like:
class CommentRequest {
public String author;
public String website;
public String comment;
}
class CommentResponse {
@Json(name="comment-id")
public String commentId;
public boolean moderated;
}
Notice that it can even deal with odd property names like "comment-id"
which would be very hard to access with js overlays.
Then you then create GWT RPC style service interfaces to access your
URL:
public interface CommentService extends RestService {
@POST @Path("/blog/comments")
public void comment(CommentRequest request,
MethodCallback<CommentResponse> callback);
}
You then create an instance use the service interface the same way
that
GWT RPC does it:
CommentService service = GWT.create(CommentService.class);
CommentRequest req = new CommentRequest
req.author = "Hiram"
req.website = "http://hiramchirino.com"
req.comment = "This is my comment."
service.comment(req, new MethodCallback<CommentResponse>() {
public void onFailure(Method method, Throwable exception) {
Window.alert("Error x: " + exception);
}
public void onSuccess(Method method, CommentResponse response) {
Window.alert("posted comment: "+response.commentId);
}
});
Hope that helped.
On Jul 5, 8:01 am, Ahmed Shoeib <[email protected]> wrote:
> Dear Friends ,
>
> i face a problem when trying to send and receive json object between
> client and server in GWT application
>
> so i want a simple example that show me how to do this
>
> Thanks,
> ahmed shoeib
--
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.