J2js - Global

2JS script include allows you to convert java objects to JavaScript objects.

If the given value is a Java object that can be converted to an equivalent JavaScript object, that conversion is performed and the result is returned. Otherwise the original Java object is returned.

The j2js class is available to server-side scripts.

The specific conversion performed in the order they are checked.
  • Java String -> JavaScript string
  • Java Boolean -> JavaScript boolean
  • Java Integer -> JavaScript number
  • Java Long -> JavaScript number
  • Java Double -> JavaScript number
  • Java Byte -> JavaScript number
  • Java Float -> JavaScript number
  • Java Short -> JavaScript number
  • Java Character -> JavaScript number
  • Java array -> JavaScript Array with order preserved
  • Java List -> JavaScript Array with order preserved
  • Java Map -> JavaScript Object with the key/value pairs translated into property/value pairs
  • Java Set -> JavaScript Array in arbitrary order

Conversions are performed recursively on the elements of arrays, lists, or collections. For example, given a Java ArrayList of ArrayLists of Strings, this will return a JavaScript Array of Arrays of strings.