My favorites | Sign in
Project Logo
                
Code license: Apache License 2.0
Labels: GWT, JSON
Show all Featured downloads:
jsonwrapper-0.1.jar
People details
Project owners:
  dkappe

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.









Hosted by Google Code