@Override public Object stringToJson(String json) { Context context = Context.getCurrentContext(); try { return new JsonParser(context, ScriptRuntime.getGlobal(context)).parseValue(json); } catch (JsonParser.ParseException e) { logger.error("Unable to create a json object from string {}", json, e); throw new IllegalArgumentException(e.getMessage(), e); } } }
private static Object parse(Context cx, Scriptable scope, String jtext) { try { return new JsonParser(cx, scope).parseValue(jtext); } catch (JsonParser.ParseException ex) { throw ScriptRuntime.constructError("SyntaxError", ex.getMessage()); } }
@Override protected Object doCall(Context cx, Scriptable scope) throws RuntimeException { try { Object obj = new JsonParser(cx, scope).parseValue(json); scope.put(varName, scope, obj); return null; } catch (ParseException e) { throw Throwables.propagate(e); } } });
private static Object parse(Context cx, Scriptable scope, String jtext) { try { return new JsonParser(cx, scope).parseValue(jtext); } catch (JsonParser.ParseException ex) { throw ScriptRuntime.constructError("SyntaxError", ex.getMessage()); } }
private static Object parse(Context cx, Scriptable scope, String jtext) { try { return new JsonParser(cx, scope).parseValue(jtext); } catch (JsonParser.ParseException ex) { throw ScriptRuntime.constructError("SyntaxError", ex.getMessage()); } }
private static Object parse(Context cx, Scriptable scope, String jtext) { try { return new JsonParser(cx, scope).parseValue(jtext); } catch (JsonParser.ParseException ex) { throw ScriptRuntime.constructError("SyntaxError", ex.getMessage()); } }
@Override public Object coerce(Object obj, Type type) { Context cx = Context.enter(); try { if (obj instanceof String) { return new JsonParser(cx, cx.initStandardObjects()).parseValue((String) obj); } return obj; } catch (ParseException e) { // just assume it's actually a string return obj; } } }