java.lang.Object
org.springframework.extensions.webscripts.json.JSONUtils

public class JSONUtils extends Object
Collection of JSON Utility methods. This class is immutable.
Author:
Roy Wetherall, Kevin Roast
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Encodes a JSON string value
    org.json.simple.JSONObject
    Converts the given JavaScript native object to a org.json.simple.JSONObject Java Object.
    Converts a given JavaScript native object and converts it to the relevant JSON string.
    org.mozilla.javascript.ScriptableObject
    toObject(String jsonString)
    Takes a JSON string and converts it to a native java script object or array
    org.mozilla.javascript.NativeArray
    toObject(org.json.simple.JSONArray jsonArray)
    Takes a JSON array and converts it to a native JS array.
    org.mozilla.javascript.NativeObject
    toObject(org.json.simple.JSONObject jsonObject)
    Takes a JSON object and converts it to a native JS object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JSONUtils

      public JSONUtils()
  • Method Details

    • toJSONString

      public String toJSONString(Object object) throws IOException
      Converts a given JavaScript native object and converts it to the relevant JSON string.
      Parameters:
      object - JavaScript object
      Returns:
      String JSON
      Throws:
      IOException
    • toJSONObject

      public org.json.simple.JSONObject toJSONObject(Object object) throws IOException
      Converts the given JavaScript native object to a org.json.simple.JSONObject Java Object. This is a specialized method only used by routines that will later expect a JSONObject.
      Parameters:
      object - JavaScript native object
      Returns:
      JSONObject
      Throws:
      IOException
    • toObject

      public org.mozilla.javascript.ScriptableObject toObject(String jsonString)
      Takes a JSON string and converts it to a native java script object or array
      Parameters:
      jsonString - a valid json string
      Returns:
      NativeObject the created native JS object that represents the JSON object or array
    • toObject

      public org.mozilla.javascript.NativeObject toObject(org.json.simple.JSONObject jsonObject)
      Takes a JSON object and converts it to a native JS object.
      Parameters:
      jsonObject - the json object
      Returns:
      NativeObject the created native object
    • toObject

      public org.mozilla.javascript.NativeArray toObject(org.json.simple.JSONArray jsonArray)
      Takes a JSON array and converts it to a native JS array.
      Parameters:
      jsonArray - the json array
      Returns:
      NativeObject the created native array
    • encodeJSONString

      public Object encodeJSONString(Object value)
      Encodes a JSON string value
      Parameters:
      value - value to encode
      Returns:
      String encoded value