我将一个对象“transformContext”从 Java 传递到 Graal.js scriptEngine。该对象包含一个名为“dataRecordsByName”的 Hashmap,在 Java 中我通常可以使用以下行访问它:
transformContext.get("dataRecordsByName")
我正在尝试从引擎中检索哈希图。我认为要做到这一点,我需要将上面的行替换为:
engine.eval("transformContext.dataRecordsByName")
然而,这只是返回未定义。
这是我完成此任务的完整代码:
ScriptEngine engine = new ScriptEngineManager().getEngineByName("graal.js");
engine.put("transformContext",transformContext);
engine.eval("console.log(transformContext)");
engine.eval("console.log(transformContext.dataRecordsByName)");
这是控制台的输出:
TransformContext(dataRecordsByName={$=[], CONVERSION=[{"From_Currency":"AUD","To_Currency":"AUD","Conversion_Rate":1.0,"historical_date":"31/05/2021","organisation_id ":"ParentId","organisation_currency":"GBP","organisation_name":"Parent Id"}],...}, objectMapper=com.fasterxml.jackson.databind.ObjectMapper@21dfdc26)
不明确的
有谁知道为什么引擎无法检索 dataRecordsByName 属性?