How to pass a Java byte[] to the ScriptEngine Nashorn as parameter?
Hao Guo
wpfmaker at gmail.com
Sat Dec 31 09:57:50 UTC 2022
This is my code to call a JavaScript function in Java:
*// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a JavaScript engine
System.setProperty("nashorn.args", "--language=es6");
ScriptEngine engine = factory.getEngineByName("Nashorn");
engine.eval("function transformPayload(rawData) { return rawData }");
Invocable invokeEngine = (Invocable) engine;
var rawData = "{\"keyOne\": \"Value one\",\"keyTwo\": \"Value
two\"}".getBytes();
return invokeEngine.invokeFunction("transformPayload", rawData);*
After I execute the script, I have a String but not a byte[], I also
can't execute the logic of processing JavaScript byte[] in this code.
How to pass a Java byte[] to the ScriptEngine Nashorn as parameter?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/nashorn-dev/attachments/20221231/31a8ead3/attachment.htm>
More information about the nashorn-dev
mailing list