Skip to content Skip to sidebar Skip to footer

Rhino - Passing A Javascript Object To Java

Im quite new to Rhino and my question is around how to achieve the following, Say I have a javascript object that follows something like the following that I can consume within jav

Solution 1:

JavaScript objects, when you access them in Java, are all essentially the same class: ScriptableObject which implements the Scriptable interface (GitHub source). There are a few other classes for functions and other specialized objects.

The Scriptable interface includes methods like get, has, and put that correspond roughly to myObject.string1, myObject.hasOwnProperty("string1"), and myObject.string1 = "Hello" in JavaScript. The ScriptableObject class adds some other useful methods for defining properties, etc.

Solution 2:

Consider using a library like GSON for converting a javascript object to JAVA.

https://code.google.com/p/google-gson/

you can convert a javascript object to JSON using JSON.stringify

and then use GSON or another such library to generate a Java object.

Post a Comment for "Rhino - Passing A Javascript Object To Java"