I am using the NodeJS interface of the J2V8 project to create a scripting sandbox inside of an Akka actor (written in Scala with the spray.json.JsObject libraries from Akka-Http). I have json coast-to-coast design for the architecture.
I have JSON objects in-scope in the actor (scala code) and would like a natural way to pass these into and out of the nodejs script via V8Objects. I have code working that passes the json objects as strings but every script needs to do the JSON.parse() call.
Scala:
import spray.json.{JsObject, JsString, JsValue}
import com.eclipsesource.v8._
// take a native json object
val text: JsObject = JsObject("key", JsString("value"))
// add it's stringified version to the runtime
nodeJS.getRuntime.add("text", text.compactPrint)
Javascript:
var msgObj = JSON.parse(text);
Is there a way to use the J2V8 API to more simply marshal back and forth between Json and V8Objects?
Note to Future Self: I am exploring J2V8 within Scala as an alternative to running Nashorn for server-side scripting support. With Nashorn, I found that 99% of javascript libraries would not work because they depend on DOM objects. Using the NodeJS interface to V8, I am able to load/use standard node modules like http/https and crypto.