org.quickconnectfamily.json
Class JSONUtilities

java.lang.Object
  extended by org.quickconnectfamily.json.JSONUtilities

public class JSONUtilities
extends java.lang.Object

This class contains several utility methods for generating and parsing JSON strings. Care has been taken to make these match the JavaScript JSON API as much as possible. Since these methods are static you may use them without worry from within any thread or in multiple threads.

Author:
Lee S. Barney

Nested Class Summary
static class JSONUtilities.encoding
          Encodings available for parsed and generated JSON Strings
 
Field Summary
static boolean isBeta
           
static int subversion
           
static int version
           
 
Constructor Summary
JSONUtilities()
           
 
Method Summary
static java.lang.String getVersion()
           
static java.lang.Object parse(java.lang.String aJSONString)
          Parses a string using the default platform encoding.
static java.lang.Object parse(java.lang.String aJSONString, JSONUtilities.encoding theEncoding)
          Parses a string using the defined encoding.
static java.lang.String stringify(java.io.Serializable aSerializableObject)
          Converts a Serializable object into a JSON formatted string
static java.lang.String stringify(java.io.Serializable aSerializableObject, JSONUtilities.encoding theEncoding)
          Converts a Serializable object into a JSON formatted string using the specified Encoding
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static int version

subversion

public static int subversion

isBeta

public static boolean isBeta
Constructor Detail

JSONUtilities

public JSONUtilities()
Method Detail

getVersion

public static java.lang.String getVersion()

stringify

public static java.lang.String stringify(java.io.Serializable aSerializableObject)
                                  throws JSONException
Converts a Serializable object into a JSON formatted string

Parameters:
aSerializableObject - - the object to be JSONed. This can be any Serializable Object except a raw Object or anything that inherits from java.awt.container.
Returns:
a JSON formatted String or if null is passed in null is returned.
Throws:
JSONException

stringify

public static java.lang.String stringify(java.io.Serializable aSerializableObject,
                                         JSONUtilities.encoding theEncoding)
                                  throws JSONException
Converts a Serializable object into a JSON formatted string using the specified Encoding

Parameters:
aSerializableObject - - the object to be JSONed. This can be any Serializable Object except a raw Object or anything that inherits from java.awt.container.
theEncoding - - the encoding to use for the desired string. It must be one of the encodings declared in JSONUtilities.encoding.
Returns:
aJSON formatted String using the desired encoding
Throws:
JSONException

parse

public static java.lang.Object parse(java.lang.String aJSONString)
                              throws JSONException
Parses a string using the default platform encoding. Either a HashMap or ArrayList is generated.

Parameters:
aJSONString - - the string to be parsed. It is assumed that aJSONString uses the default encoding for the platform.
Returns:
either a HashMap or an ArrayList depending on the contents of the parameter string
Throws:
JSONException

parse

public static java.lang.Object parse(java.lang.String aJSONString,
                                     JSONUtilities.encoding theEncoding)
                              throws JSONException
Parses a string using the defined encoding. Either a HashMap or ArrayList is generated.

Parameters:
aJSONString - - the string to be parsed. For normal behavior it must be in the encoding declared as the theEncoding parameter.
theEncoding - - the encoding of the String passed in as aJSONString. It must be one of the encodings declared in JSONUtilities.encoding.
Returns:
either a HashMap or an ArrayList depending on the contents of the parameter string
Throws:
JSONException