The GWT docs are offering you to use the JavaScript "eval" function directly
or through the JSONParser class, which internally uses the "eval" function.
A more secure way, that is to use the JSON library
http://www.json.org/js.html. You'll place the additional JavaScript library
in your host page, as any other JavaScript too. Than take the code from the
GWT docs:
private final native JsArray<StockData> asArrayOfStockData(String json) /*-{
return *eval(json);*
}-*/;
and modify it like this:
private final native JsArray<StockData> asArrayOfStockData(String json) /*-{
return *$wnd.JSON.parse(json);*
}-*/;
This is more secure than using the "eval" function. Additionally the
"JSON.parse()" function has become part of the JavaScript standard and is
implemented natively in many modern browsers. The above library knows this
and delegates the secure JSON parsing to the fast native parser provided by
the browser.
Regards
Jan Ehrhardt
2010/6/18 Chris Boertien <[email protected]>
> Is there a particular reason that you _need_ the JSON string? If your
> using GWT RPC then you can simply send a Java Object to the server and
> the underlying GWT will handle the serialization for you.
>
> If you the JSON string is coming from somewhere else and you really
> have no choice, then it may be worthwhile to put together a JSO
> Overlay, use the Overlay to instantiate a POJO on the client side
> code, and send the POJO to the server via GWT RPC.
>
> Since your new some of that probably makes no sense, and If you can
> give a little more detail as to why you need to have JSON originating
> from the client I'm sure this can be explained a bit better to fit
> your case.
>
> GWT-RPC: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html
> GWT-JSON:
> http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.html#client
>
> 2010/6/16 Jose Luis Estrella Campaña <[email protected]>:
> > Hello Folks !
> >
> > I'm glad to say that I'm a brand new user of GWT, a very happy one by
> > the way. However, as any newcomer I have questions, One in particular.
> > Here it goes:
> >
> > What's the easiest, most straight forward way to deserialize a JSON
> > String on the Server side and instance a Java Object from it ?
> >
> > The JSON String will be sent from the client side, an implementation
> > of the RemoteService for example, and I intend to deserialize it on
> > the Server side, say inside the RemoteServiceServlet Implementation,
> > so I can instance a Java Object with the information contained in the
> > JSON string afterwards. Is there a way this last step automatically
> > with some GWT API ?
> >
> > I would like to see some examples if it's possible.
> >
> > Best Regards,
> >
> > Sincerely,
> >
> > Jose.
> >
> > --
> > 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]<google-web-toolkit%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
> >
> >
>
> --
> 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]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
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.