ro.isdc.wro.extensions.script
Class RhinoUtils

java.lang.Object
  extended by 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 ://mongodb-rhino.googlecode.com/svn/trunk/modules/com.mongodb.rhino/src/com/mongodb/rhino/JSON.java

Since:
1.3.6
Author:
Alex Objelean

Method Summary
static String createExceptionMessage(org.mozilla.javascript.RhinoException e)
          Creates a more detailed message based on RhinoException thrown by rhino execution.
static String toJson(Object object)
          Recursively convert from native Rhino to JSON.
static String toJson(Object object, boolean indent)
          Recursively convert from native Rhino to JSON.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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
See Also:
RhinoUtils#convertSpecial(Object)

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


Copyright © 2008-2013. All Rights Reserved.