Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building JSON server-side with Google Web Toolkit

Tags:

json

gwt

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.

like image 757
Derek Thurn Avatar asked Jul 18 '10 16:07

Derek Thurn


1 Answers

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.

like image 160
Jason Hall Avatar answered Sep 20 '22 20:09

Jason Hall