Monday, January 4, 2010

Re: RPC vs HTTP requests

On Jan 4, 4:01 pm, Jeff Chimene <jchim...@gmail.com> wrote:
>
> I have a question:
> <snip>
>
> > *Performance*
>
> >    - Client Side - REST with JSON wins over RPC. Browsers are
> >    exceptionally good at json parsing. It is going to be much faster than GWTs
> >    serialization/deserialization mechanism. This is applicable only if you use
> >    javascript overlays. JSONArray/JSONObject/JSONValue classes don't give you
> >    this performance benefit.
>
> I've been using the following technique to use the JSON parsing in 2.0. I
> don't see a specific example in the docs:
>
> Report.set(JSONParser.parse(response.getText()).isObject().getJavaScriptObj ect());
>
> Where Report is defined as follows:
>
> public class Report extends JavaScriptObject {
>
>     protected Report() {}
>
>     public final static native Report get() /*-{
>         return $wnd.Report;
>     }-*/;
>
>     public final static native void set(JavaScriptObject value) /*-{
>         $wnd.Report = value;
>     }-*/;
>
> }
>
> I don't see any other way to avoid unsafe parsing.
>
> Comments?

Use JsonUtils.unsafeEval() to avoid the unused JSONObject created by
JSONParser.parse(), and then just use .cast() to turn the JSO into a
Report (unless of course you want a singleton in the $wnd.Report
global JS variable):

Report myReport = JsonUtils.unsafeEval(response.getText()).cast();

--

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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate