use of com.googlecode.gwt.test.exceptions.GwtTestJSONException in project gwt-test-utils by gwt-test-utils.
the class JSONParserPatcher method evaluate.
@PatchMethod
static JSONValue evaluate(String json, boolean strict) {
JsonParser jp = null;
try {
JsonFactory f = new JsonFactory();
if (!strict) {
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
f.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
f.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
f.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true);
}
jp = f.createJsonParser(json);
// will return JsonToken.START_OBJECT (verify?)
jp.nextToken();
JSONObject jsonObject = extractJSONObject(json, jp);
return jsonObject;
} catch (Exception e) {
if (e instanceof GwtTestException) {
throw (GwtTestException) e;
}
throw new GwtTestJSONException("Error while parsing JSON string '" + json + "'", e);
} finally {
if (jp != null) {
try {
// ensure resources get cleaned up timely and properly
jp.close();
} catch (IOException e) {
// should never happen
}
}
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestJSONException in project gwt-test-utils by gwt-test-utils.
the class JsonUtilsPatcher method eval.
private static <T extends JavaScriptObject> T eval(String json) {
JsonParser jp = null;
try {
jp = getFactory().createJsonParser(json);
// will return JsonToken.START_OBJECT (verify?)
jp.nextToken();
return extractJso(json, jp.getCurrentToken(), jp).<T>cast();
} catch (Exception e) {
if (e instanceof GwtTestException) {
throw (GwtTestException) e;
}
throw new GwtTestJSONException("Error while parsing JSON string '" + json + "'", e);
} finally {
if (jp != null) {
try {
// ensure resources get cleaned up timely and properly
jp.close();
} catch (IOException e) {
// should never happen
}
}
}
}
Aggregations