Notice: This is an old project and it is not relevant any more. I uploaded it to GitHub because I shut down the original homepage of the project.
Gwt-json-rpc is a simple json-rpc implementation for the Google Web Toolkit (GWT). Because I started writing this module before GWT contained an JSON encoder, it contains an own JSON encoder and decoder. The decoder is a modified version of the JSONParser from the GWT examples. The encoder is written from scratch. The main difference to the GWT JSON en-/decoder is that you don't have to use JSONObject, JSONArray, JSONString, rather you can use native Java types like String, int, boolean, Array, HashMap, ArrayList, Vector and so on for encoding and decoding data.
//Create a new JsonRpc instance
JsonRpc jsonRpc = new JsonRpc();
//Create a callback handler
AsyncCallback callback = new AsyncCallback() {
public void onFailure(Throwable caught) {
label.setText("Error: " + caught);
};
public void onSuccess(Object result) {
//Cast the result to an Integer an display it
Integer total = (Integer) result;
label.setText("Total: " + total);
};
};
//Send the request. In this case the method 'total' is called
//which takes one parameter, an int array, and returns
//the total of all int values in the array.
jsonRpc.request(
"http://www.raboof.com/Projects/Jayrock/Demo.ashx",
"total",
new Object[] { new int[] {3, 6} },
callback);