public class Serializer { static public Map<String, Object> object2Map(NativeObject o) { Map<String, Object> ret = new HashMap<>(); for(Object keyField: o.getAllIds()) { try { Object valObject = o.get(keyField.toString()); ret.put(keyField.toString(), valObject); } catch (Exception e) { continue; } } return ret; } }
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.SimpleBindings; import sun.org.mozilla.javascript.internal.NativeObject; String buildInfoJS = "var build_info = new Object;build_info.BUILD_DISPLAY_VERSION = 'Build 201302232300'"; ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine jsEngine = mgr.getEngineByName("JavaScript"); jsEngine.eval(buildInfoJS); Object nativeObject = jsEngine.get("build_info"); if (nativeObject instanceof NativeObject) { NativeObject nObj = (NativeObject)nativeObject; for (String key: nObj.getAllIds()) { System.out.println(key); System.out.println(nObj.get(key, nObj)); } }
CompiledScript script = compEngine.compile(TEST_SCRIPT); NativeObject obj = (NativeObject) script.eval(); NativeArray obj1 = (NativeArray) obj.get(obj.getAllIds()[0]); for (Object temp : obj1) { NativeObject obj2 = (NativeObject) temp;
for (Object id : ((NativeObject)resultObject).getAllIds()) { if (! (id instanceof String)) { throw new RuntimeException("ARGH: " + id);
for (Object id : ((NativeObject)resultObject).getAllIds()) { if (! (id instanceof String)) { throw new RuntimeException("ARGH: " + id);
Object[] allIds = no.getAllIds(); for (Object currentAttributeKey: allIds)
Object[] allIds = no.getAllIds(); for (Object currentAttributeKey: allIds)