My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

Utility wrapper to make writing JSONValue code less verbose. Read the original blog article for more information or the getting started page in the wiki.

You might find the Javadoc for JSONWrapper to be moderately useful.

Motivation

Wrapper for GWT's JSONValue class. This class allows for the easy chaining of operators without having to constantly check for null return values. So, instead of typical JSONValue code

JSONValue root = JSONParser.parse(json);
JSONObject obj = root.isObject();
if (obj != null) {
    JSONValue map = obj.get("map");
    if (map != null) {
        JSONArray arr = map.isArray();
        if (arr != null) {
            if (arr.size() > 1) {
                JSONValue strval = arr.get(1);
                if (strval != null) {
                    JSONString str = strval.isString();
                    if (str != null) {
                        String s = str.stringValue();
                        // do something with the string
                    }
                }
            }
        }
    }
}

we can write something like

JSONValue root = JSONParser.parse(json);
JSONWrapper obj = new JSONWrapper(root);
String result = obj.get("map").get(1).stringValue();

without having to worry about NullPointerException's cropping up all over the place.

Powered by Google Project Hosting