Class RhinoUtils

java.lang.Object
ro.isdc.wro.extensions.script.RhinoUtils

public class RhinoUtils extends Object
Direct conversion between native Rhino objects and JSON.

This class can be used directly in Rhino.

This class was inspired from http://mongodb-rhino.googlecode.com/svn/trunk/modules/com.mongodb.rhino/src/com/mongodb/rhino/JSON.java

Since:
1.3.6
Author:
Alex Objelean
  • Method Details

    • createExceptionMessage

      public static String createExceptionMessage(org.mozilla.javascript.RhinoException e)
      Creates a more detailed message based on RhinoException thrown by rhino execution. The message will contain a detailed description of the problem by inspecting the JSON value provided by exception.
      Parameters:
      e - RhinoException thrown by rhino execution.
      Returns:
      detailed string message.
    • toJson

      public static String toJson(Object object)
      Recursively convert from native Rhino to JSON.

      Recognizes JavaScript objects, arrays and primitives.

      Special support for JavaScript dates: converts to {"$date": timestamp} in JSON.

      Special support for MongoDB ObjectId: converts to {"$oid": "objectid"} in JSON.

      Also recognizes JVM types: java.util.Map, java.util.Collection, java.util.Date.

      Parameters:
      object - A Rhino native object
      Returns:
      The JSON string
    • toJson

      public static String toJson(Object object, boolean indent)
      Recursively convert from native Rhino to JSON.

      Recognizes JavaScript objects, arrays and primitives.

      Special support for JavaScript dates: converts to {"$date": timestamp} in JSON.

      Special support for MongoDB ObjectId: converts to {"$oid": "objectid"} in JSON.

      Also recognizes JVM types: java.util.Map, java.util.Collection, java.util.Date.

      Parameters:
      object - A Rhino native object
      indent - Whether to indent the JSON for human readability
      Returns:
      The JSON string