JSON Parsing in GWT Client

2,691 views
Skip to first unread message

Santosh

unread,
May 21, 2012, 8:08:00 AM5/21/12
to Google Web Toolkit
We have use GWT Platform with GWTP client and rest web services within
GUICE container. Rest service invocation from GWT client is done using
JSONPRequestbuilder.

I want to know which is the best JSON response string parsing
technique for GWT? - JSON to Java serialization/deserialization

After lot of search on google, I found out that we have these many
options.

a. GWT built in JSONParser parseStrict method which is called secured
and best way to go. But this may not be suitable for complex JSON
response string. Becuase you need to write lot of code to parse each
item in JSON response and convert to a Java object.
b. GWT AutobeanFactory approach - I dont know how best to use this? We
are using GWT 2.4, you do not have any complete example of using this
approach at all. Everywhere, people say its an approach but no where
we have detailed description on this. Few samples on google were from
gwt older versions which were changed a lot in GWT 2.4. Please
somebody share a good example with GWT 2.4 and Autobean factory
approach for JSON ser/deser...
c. JavaScript overlay types: People say it is not the secured way to
go. So I am bit hesitate whether we should use this or not.

Moreover, we are migrating from GWT to SmartGWT very soon. I hope, the
rest call services with these should continue to work even in SmartGWT
without any changes. (Because SmartGWT also comes with a predefined
format JSON rest support which we may not use as we already have built
these services in general).

Kindly advice asap.

Thanks

Ümit Seren

unread,
May 23, 2012, 10:34:35 AM5/23/12
to google-we...@googlegroups.com
Both AutoBeanFactory as well as JSO are secure and suitable for parsing JSON. 
The good thing about AutoBeanFactory is that you can also use on the backend to encode objects as JSON. 
Did you check the official google docs on AutoBeans (http://code.google.com/p/google-web-toolkit/wiki/AutoBean)? 
Another approach I have been using in my projects (GWTP) is Harald Pehl's piriti library (http://code.google.com/p/piriti/). 

dominikz

unread,
May 24, 2012, 2:56:53 AM5/24/12
to google-we...@googlegroups.com
I was just having the same problem. I evaluated the solutions yesterday and frankly speaking was surprised by the lack of straight answers from both GWT documentation and the internet. 
The number of projects there are is just amazing, but nothing seems to stand out.

In the end I wanted to use Piriti. However, we've had problems with using it with XML parsing on Android. Our applications work mainly on phone browsers, so lack of support for XPath on some phone struck us really hard. However with JSON it's different. We were kind of resistant after having a bad experience with phones+piriti+XML, but it seems that phones+piriti+JSON work. We just checked it on Android (Native browser, Opera Mobile and Opera Mini) on Samsung's Bada and on iPhone (Native Browser) and the test passed OK.

So given that piriti's code looks really nice and it's easy to switch between JSON and XML (if we ever needed),we'll try to go with that.

One issue we still have not resolved is the performance. We started with XML in the payload, since our apps work on SAP (ABAP is the language there) and it's easy to do XML on the backend rather than JSON. However, parsing of XML in the browser was not possible with piriti on some mobile platforms (Android) and using DOM library was both time consuming to code and really slow. Parsing of our payload took 5-7 secs on Android. This was unacceptable. That's why the switch to JSON.

The thing we'll test right now is piriti+JSON performance. I'm not sure how piriti does the parsing, but it might be that other frameworks do it faster/slower.

If anyone has an answer to the PERFORMANCE question of piriti+JSON, I'd be glad to hear.

dominikz

unread,
May 24, 2012, 3:36:56 AM5/24/12
to google-we...@googlegroups.com
And by the lack of straight answers I mean that.

Take a look at the number of projects listed in comments under the post:


Surely, to evaluate all of them would take a week at least.

Thomas Broyer

unread,
May 24, 2012, 4:52:29 AM5/24/12
to google-we...@googlegroups.com


On Thursday, May 24, 2012 8:56:53 AM UTC+2, dominikz wrote:
I was just having the same problem. I evaluated the solutions yesterday and frankly speaking was surprised by the lack of straight answers from both GWT documentation and the internet. 
The number of projects there are is just amazing, but nothing seems to stand out.

AutoBean is the technology backing RequestFactory; it's stable and has very few known bugs in 2.4 (one or two, no more; all being already fixed in trunk; this is an all different story for RequestFactory).
I just think nobody had/took the time to copy the wiki page to the dev guide at developers.google.com/web-toolkit.

dominikz

unread,
May 24, 2012, 5:07:06 AM5/24/12
to google-we...@googlegroups.com
Thanks Thomas,

we're now doing performance comparision between AutoBean and Piriti. 
We still don't know whether there will be problems with AutoBean on mobile devices - I guess not.

Do you know of any streghts/weaknesses of piriti/AutoBean?

dominikz

unread,
May 24, 2012, 8:24:22 AM5/24/12
to google-we...@googlegroups.com
Just got performance results for various browsers and devices.
If you're interested please take a look here:

Harald Pehl

unread,
May 24, 2012, 3:04:48 PM5/24/12
to google-we...@googlegroups.com
Thanks for the numbers  It's quite interesting for me to see how Piriti performs compared to AutoBeans. In recent versions, I've added new features mainly (right now I'm working on JAXB support). Regarding performance there's still room for improvement. The problem is that Piriti is currently a one-man-show and my time is limited.

Nevertheless I'm happy to see that Piriti is actively used. If you have any questions don't hesitate to ask.

- Harald (author of Piriti)

dominikz

unread,
May 25, 2012, 1:13:04 AM5/25/12
to google-we...@googlegroups.com
Don't get me wrong. One of my developers was evaluating JSON frameworks. He really liked pirity due to the fact that you can annotate fields there and not setters and getters like in AutoBean. He fealt that it's just too much code. I know this discussion is academic, but that's how he feels.

I'm also not sure whether you can plug in custom code formatters in AutoBeans as easily as in piriti.

So if it wasn't for performance we'd use piriti. Especially because it's so easy to switch to XML.

The reason why performance is so important for us is because our apps are on mobile. This parsing time can easily make the app seem unresponsive to the user. 

If we were writing for desktop browsers, we probably wouldn't care so much about each millisecond of parsing.

I guess what I wanted to say is that you've done a really good job with piriti. I know it's hard to fight with a group of hired google developers.


dominikz

unread,
May 25, 2012, 1:14:39 AM5/25/12
to google-we...@googlegroups.com
Nevertheless I'm happy to see that Piriti is actively used. If you have any questions don't hesitate to ask.


Actually I have. Do you know why AutoBeans is much faster?
Can you share some details? You know your implementation better then all of us.

dominikz

unread,
May 25, 2012, 3:07:09 AM5/25/12
to google-we...@googlegroups.com
Looking at the data it seems that piriti JSON parsing is as slow as piriti XML parsing. Generally XML dom parsing (without using piriti) is way slower than any JSON. 

Maybe this is a clue?

Harald Pehl

unread,
May 25, 2012, 5:22:20 AM5/25/12
to google-we...@googlegroups.com
The actual parsing is done using GWT JSON API: JSONParser.parseStrict(String). I guess AutoBean does nothing different regarding parsing. I think the time conssuming parts in Piriti are related to resolving relations between objects and handling IDs and IDREFs. Although there are no real ID and IDREFs in JSON the code is pretty much the same for JSON and XML. This part could certainly be optimized. 

I will try to further analyze the hot spots in one of the next releases.

- Harald

Raphael André Bauer

unread,
May 25, 2012, 7:03:58 AM5/25/12
to google-we...@googlegroups.com
Hi,


the solution is really simple:
Use resty gwt: https://github.com/chirino/resty-gwt

A sample project including GWT configuration can be found here:
http://code.google.com/p/play-gae-gwt-dreamteam-showcase

restygwt drives one of the biggest websites in Germany. We never had
any performance issues.


Cheers,

Raphael
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/I6JfHi2Gw4QJ.
>
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.



--
inc: http://ars-machina.raphaelbauer.com
tech: http://ars-codia.raphaelbauer.com
web: http://raphaelbauer.com

Alex opn

unread,
May 25, 2012, 9:52:46 AM5/25/12
to google-we...@googlegroups.com
"restygwt drives one of the biggest websites in Germany. We never had
any performance issues."

You can't say which one, i suggest? :) Would be interesting to know.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsub...@googlegroups.com.

Jens

unread,
May 25, 2012, 10:57:17 AM5/25/12
to google-we...@googlegroups.com
"restygwt drives one of the biggest websites in Germany. We never had
any performance issues."

You can't say which one, i suggest? :) Would be interesting to know.

Just a guess: probably studivz.net / meinvz.net. Its a german social network and has been rewritten in GWT some time ago. But you have to sign up and log in to switch to the new GWT version and see it in action. They use Rest like requests and they have forked restygwt on github (https://github.com/vznet).

-- J.
Reply all
Reply to author
Forward
0 new messages