tags:

views:

114

answers:

2

Google Web Toolkit has a JSON library (com.google.gwt.json.client). The 'client' part of that name makes me suspect that it isn't intended for use server-side. The following code in a server-side RPC method confirms my suspicions:

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

By throwing a ClassNotFound(JSONArray) exception. I need to build some JSON server-side.

1) Am I correct in believing that I can't use the com.google.gwt.json.client package on the server? 2) If so, is there a good alternative with approximately the same interface that I can use to construct JSON on the server?

I'm running my app on App Engine, in case it matters.

A: 

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

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

It seems to compile OK for App Engine. I'm not 100% sure, but I'm fairly confident that the GWT-bundled JSON library cannot be used server side, which is quite strange.

Derek Thurn
A: 

1) Am I correct in believing that I can't use the com.google.gwt.json.client package on the server?

Correct. That class contains lots of native JS methods -- important stuff like get() -- and is meant to be compiled down to JavaScript to be used in the client side.

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

Jason Hall