7

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.

1

3 Answers 3

3

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.

0
1

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.

1

One of the best options to use is to use RestyGWT on the client side and Jackson on the sever side. That way you get transparent object to JSON marshaling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.