@Test @SuppressWarnings("unchecked") public void testUnwrapMap() throws ScriptException, NoSuchMethodException { engine.eval("function test() { return {'key1':'value', 'key2': {'subKey': 'subValue'}}; }"); ScriptObjectMirror object = (ScriptObjectMirror) ((Invocable) engine).invokeFunction("test"); Map<String, Object> map = ScriptObjectMirrors.unwrapMap(object); assertEquals("value", map.get("key1")); assertNotNull(map.get("key2")); assertEquals("subValue", ((Map<String, Object>) map.get("key2")).get("subKey")); }
public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map); }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map);  }