Creating the JSON back end using the Google Web Toolkit

The Google Web Toolkit has a JSON library (com.google.gwt.json.client). The "client" part of this name makes me suspect that it is not intended to be used on the server side. The following code in the server-side RPC method confirms my suspicions:

System.out.println("attempting to make JSONArray"); JSONArray test = new JSONArray(); System.out.println("Made JSONArray"); 

Throwing a ClassNotFound exception (JSONArray). I need to build a part of the JSON server.

1) Do I correctly believe that I can not use the com.google.gwt.json.client package on the server? 2) If yes, is there a good alternative with about the same interface that I can use to build JSON on the server?

I run my application in App Engine, if that matters.

+6
json gwt
source share
3 answers

1) Do I correctly believe that I can not use the com.google.gwt.json.client package on the server?

Correctly. This class contains many native JS methods - important things like get() - and is intended to be compiled using JavaScript, which will be used on the client side.

As for 2), as you already found, the library you found on json.org is good, and I also heard promising things about gson .

+3
source share

I ended up using the Java library with JSON.org:

http://www.json.org/java/

It seems to be compiling OK for App Engine. I am not 100% sure, but I am sure that the GWT package JSON library cannot be used on the server side, which is rather strange.

+1
source share

One of the best use cases is to use RestyGWT on the client side and Jackson on the north side. This way you get a transparent object for JSON marshaling.

+1
source share

All Articles