org.starhope.appius.util
Class JSONUtil

java.lang.Object
  extended by org.starhope.appius.util.JSONUtil

public class JSONUtil
extends Object

This class contains static helper functions for converting various types of data to/from JSON form.

Author:
brpocock@star-hope.org

Constructor Summary
JSONUtil()
           
 
Method Summary
static javax.servlet.http.Cookie toCookie(org.json.JSONObject object)
           
static Date toDate(org.json.JSONObject o)
          This is an utility method to convert a JSON object which we have created from an SQL Date value back into an SQL Date value.
static com.google.gwt.json.client.JSONObject toGoogle(org.json.JSONObject in)
           
static org.json.JSONObject toJSON(javax.servlet.http.Cookie c)
           
static org.json.JSONObject toJSON(Date when)
          This is an utility method to convert a Time value (java.sql.Time) into a JSONObject.
static org.json.JSONObject toJSON(Set<String> data)
          Convert a set of strings into a JSONArray
static org.json.JSONObject toJSON(String[] strings)
          This is an utility method to convert an array of Strings into a JSONObject, as a compatibility layer for Smartfox.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONUtil

public JSONUtil()
Method Detail

toCookie

public static javax.servlet.http.Cookie toCookie(org.json.JSONObject object)
Parameters:
object - A JSON representation of a Cookie
Returns:
the Cookie back in Java form

toDate

public static Date toDate(org.json.JSONObject o)
                   throws org.json.JSONException
This is an utility method to convert a JSON object which we have created from an SQL Date value back into an SQL Date value.

Parameters:
o - The JSON Object
Returns:
the Date object representing the same date & time value
Throws:
org.json.JSONException - if the JSON data is badly-formed

toGoogle

public static com.google.gwt.json.client.JSONObject toGoogle(org.json.JSONObject in)
Parameters:
in - the JSON object in JSON.Org form
Returns:
the JSON object in Googley form

toJSON

public static org.json.JSONObject toJSON(javax.servlet.http.Cookie c)
                                  throws org.json.JSONException
Parameters:
c - A Cookie object to be converted to JSON
Returns:
that Cookie
Throws:
org.json.JSONException - if the data can't be stored successfully

toJSON

public static org.json.JSONObject toJSON(Date when)
                                  throws org.json.JSONException
This is an utility method to convert a Time value (java.sql.Time) into a JSONObject. Implementation note: We just store the Unix time (seconds since the epoch of 1970-01-01 00:00:00 UCT/GMT) in a single field. The broken-down date and time values are not included.

Parameters:
when - The Time to be converted
Returns:
a JSON object representing the given Time.
Throws:
org.json.JSONException - If the data cannot be represented in JSON for some reason

toJSON

public static org.json.JSONObject toJSON(Set<String> data)
                                  throws org.json.JSONException
Convert a set of strings into a JSONArray

Parameters:
data - The string set to be converted
Returns:
A JSON array of strings
Throws:
org.json.JSONException - if the data cannot be represented in JSON

toJSON

public static org.json.JSONObject toJSON(String[] strings)
                                  throws org.json.JSONException
This is an utility method to convert an array of Strings into a JSONObject, as a compatibility layer for Smartfox.

Parameters:
strings - An array of Strings
Returns:
A JSONObject representing the same data
Throws:
org.json.JSONException - if the data can't be represented in JSON