Client Server Communication - Best practice

143 views
Skip to first unread message

Will

unread,
Oct 7, 2010, 5:45:47 AM10/7/10
to Google Web Toolkit
Hi,

I have a question about using serializable objects vs JSON.

The tutorials demonstrate the use of JSON for client server
communication as well as serialized objects.
My question concerns is there a best practice around using JSON vs
serialized objects? When would one be better using JSON?

My data can be constructed quite simply using a java Map of
ints ,longs, Strings etc or by instantiating a simple object and
making it serializable..I don'tt see the benefit of using JSON unless
there is some performance reason?

Any help appreciated...

Thanks,

jocke eriksson

unread,
Oct 7, 2010, 6:56:18 AM10/7/10
to google-we...@googlegroups.com
well you can't send a ObjectOutputstream to the client :). gwt does not run in a jvm. 

2010/10/7 Will <shatner...@gmail.com>

--
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-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.


jocke eriksson

unread,
Oct 7, 2010, 6:59:20 AM10/7/10
to google-we...@googlegroups.com
So you have to send it in some other format GWT rpc or JSON. JSON has the advantage that it's not dependent on GWT. 

2010/10/7 jocke eriksson <joc...@gmail.com>

Will

unread,
Oct 7, 2010, 7:23:25 AM10/7/10
to Google Web Toolkit
Hi Jocke,

Thanks for the reply...



Ok Jocke... thanks for your reply...

I think you answered my question with your second post..

GWT rpc vs JSON...

The main advantage of using JSON over GWT RPC (serialize the objects)
is that JSON is not GWT dependent...??
Am I correct in this?

ref: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html#serialize

"Based on the requirements for serialization, what do you need to do
to make the StockPrice class ready for GWT RPC? Because all its
instance fields are primitive types, all you need to do in this case
is implement the Serializable or IsSerializable interface."

On Oct 7, 11:59 am, jocke eriksson <jock...@gmail.com> wrote:
> So you have to send it in some other format GWT rpc or JSON. JSON has
> the advantage that it's not dependent on GWT.
>
> 2010/10/7 jocke eriksson <jock...@gmail.com>
>
> > well you can't send a ObjectOutputstream to the client :). gwt does not run
> > in a jvm.
>
> > 2010/10/7 Will <shatner.will...@gmail.com>
>
> > Hi,
>
> >> I have a question about using serializable objects vs JSON.
>
> >> The tutorials demonstrate the use of JSON for client server
> >> communication as well as serialized objects.
> >> My question concerns is there a best practice around using JSON vs
> >> serialized objects? When would one be better using JSON?
>
> >> My data can be constructed quite simply using a java Map of
> >> ints ,longs, Strings etc or by instantiating a simple object and
> >> making it serializable..I don'tt see the benefit of using JSON unless
> >> there is some performance reason?
>
> >> Any help appreciated...
>
> >> Thanks,
>
> >> --
> >> 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-we...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>
> >> .

Will

unread,
Oct 7, 2010, 7:26:45 AM10/7/10
to Google Web Toolkit
this thread is also helpful...

http://stackoverflow.com/questions/2955071/gwt-rpc-vs-http-call-which-is-better

Thanks a lot for your replies...

Thomas Broyer

unread,
Oct 7, 2010, 9:31:49 AM10/7/10
to Google Web Toolkit
It (almost) only will be if you use JavaScript Overlay Types on the
client side (you can then parse from JSON using JsonUtils, and
serialize to JSON using either –a bit hackish– new
JSONObject(myObj).toString() or your own toJSON method, concatenating
to a StringBuilder with the help of JsonUtils.escapeValue).

GWT-RPC brings you "integrity checks" (it'll fail if the server and
clients do not use the same version of the class; which can also be a
drawback) and you don't have to think about how you serialize/
deserialize your objects.
...and more importantly, GWT-RPC gives you an RPC approach, something
you'd have to do yourself if you use RequestBuilder (and want RPC).

Note that with GWT 2.1 comes RequestFactory, which uses JSON with
overlay types under the cover (you code against interfaces on the
client side, and GWT will generate overlay types that implement the
interfaces; on the server-side you code against concrete classes that
have the same getters/setters as the interfaces on the client-side –
but are not required to implement any interface or have any
annotation; and they can contain server-only code, contrary to GWT-
RPC–; and it's all JSON on the wire). But RequestFactory is quite
specialized to work with "entity objects"; it's not a generic RPC
service, unlike GWT-RPC.

If you're on a ReST mood, then neither GWT-RPC nor RequestFactory will
be good for you, and then I'd recommend using JSON as explained above
(I did it on a project, but "plugged" it under an RPC-like interface
for my client code, because actually RPC is much more natural from a
coding perspective)

jocke eriksson

unread,
Oct 7, 2010, 10:49:44 AM10/7/10
to google-we...@googlegroups.com
Yes but I would actually recommend using javascript objects instead of
JSON, this is because they can have
transitive dependencies(I think it's called) where Object A can have
a Object B and B can have a Object A.
I use stripes for this feature. Look at the JavascriptResolution.

Regards Jocke.


2010/10/7 Will <shatner...@gmail.com>

> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

Will

unread,
Oct 7, 2010, 10:58:11 AM10/7/10
to Google Web Toolkit
Thanks for all the replies guys...

On Oct 7, 3:49 pm, jocke eriksson <jock...@gmail.com> wrote:
> Yes but I would actually recommend using javascript objects instead of
> JSON, this is because they can have
> transitive dependencies(I think it's called) where  Object A can have
> a Object B and B can have a Object A.
> I use stripes for this feature. Look at the JavascriptResolution.
>
> Regards Jocke.
>
> 2010/10/7 Will <shatner.will...@gmail.com>
>
>
>
> > this thread is also helpful...
>
> >http://stackoverflow.com/questions/2955071/gwt-rpc-vs-http-call-which...
Reply all
Reply to author
Forward
0 new messages