Tuesday, August 27, 2013

Re: JSON object to AutoBean via JSNI in DevMode



On Tuesday, August 27, 2013 10:21:28 AM UTC+2, Jens wrote:
Hi,

is there anything faster than

final String payload = new JSONObject(jsonDataFromJSNI).toString();
dataBean = AutoBeanCodex.decode(factory, Data.class, payload);

when in DevMode? The JSON data is embedded into the host page and not that tiny (worst case ~600kb uncompressed) and the above solution makes DevMode hang for about 3-5 seconds when refreshing the site. Thats kind of annoying and I just want to make sure I didn't miss a different solution for DevMode thats maybe faster.

Use native JSON.stringify through JSNI?
The problem with com.google.gwt.json is that it creates a lot of objects and uses a lot of JSNI which slows down DevMode.


If you don't mind running a patched GWT, there are a few issues that need to be fixed (most of them have pending reviews):
  • Elemental JSON can't be used without bringing the whole Elemental (which breaks DevMode): https://gwt-review.googlesource.com/4210
  • Some of Elemental JSON is broken in prod mode (OK, not really relevant here): https://gwt-review.googlesource.com/4050
  • Some of Elemental JSON is broken in dev mode: https://code.google.com/p/google-web-toolkit/issues/detail?id=7484 (partly fixed by above review)
Once that's fixed, you could then use: payload = ((JsJsonValue) jsonDataFromJSNI).toJson(); (note: uses JSON.stringify under-the-hood)

The next step will be to "port" AutoBean to use elemental.json instead of org.json and add an overload to AutoBeanCodex.decode that takes a JsonValue.

(side note: the data you get from the page is JS, not JSON; JSON is a serialization format, if you have objects, then it's JS, possibly expressed as JS literals; this is one reason why JSON-P is completely misnamed: there's no JSON in JSON-P, at all)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment