org.alfresco.bm.json
Class JSONUtil

java.lang.Object
  extended by org.alfresco.bm.json.JSONUtil

public class JSONUtil
extends Object

Utilities for JSON-parsing.

Author:
Frederik Heremans

Field Summary
static String FORM_PROCESSOR_JSON_PERSISTED_OBJECT
           
static String HEADER_ACCEPT
           
static String HEADER_CONTENT_TYPE
           
static String JSON_DATA
           
static String JSON_ID
           
static String JSON_ITEMS
           
static String JSON_NAME
           
static String MIME_TYPE_JSON
           
 
Constructor Summary
JSONUtil()
           
 
Method Summary
static org.json.simple.JSONArray getArray(org.json.simple.JSONObject json, String key)
           
static org.json.simple.JSONArray getDataArrayFromResponse(org.apache.commons.httpclient.HttpMethod method)
          Extract the "data" JSON-array from the method's response.
static org.json.simple.JSONObject getDataFromResponse(org.apache.commons.httpclient.HttpMethod method)
          Extract the "data" JSON-object from the method's response.
static org.json.simple.JSONObject getObject(org.json.simple.JSONObject json, String key)
           
static org.json.simple.JSONObject getObjectFromResponse(org.apache.commons.httpclient.HttpMethod method)
          Extract JSON-object from the method's response.
static String getString(org.json.simple.JSONObject json, String key, String defaultValue)
          Gets a string-value from the given JSON-object for the given key.
static void populateRequestBody(org.apache.commons.httpclient.methods.EntityEnclosingMethod method, org.json.simple.JSONObject object)
          Adds the JSON as request-body the the method and sets the correct content-type.
static void setJSONExpected(org.apache.commons.httpclient.HttpMethod method)
          Sets a header to notify server we expect a JSON-repsponse for this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_DATA

public static final String JSON_DATA
See Also:
Constant Field Values

JSON_ID

public static final String JSON_ID
See Also:
Constant Field Values

JSON_ITEMS

public static final String JSON_ITEMS
See Also:
Constant Field Values

JSON_NAME

public static final String JSON_NAME
See Also:
Constant Field Values

FORM_PROCESSOR_JSON_PERSISTED_OBJECT

public static final String FORM_PROCESSOR_JSON_PERSISTED_OBJECT
See Also:
Constant Field Values

MIME_TYPE_JSON

public static final String MIME_TYPE_JSON
See Also:
Constant Field Values

HEADER_ACCEPT

public static final String HEADER_ACCEPT
See Also:
Constant Field Values

HEADER_CONTENT_TYPE

public static final String HEADER_CONTENT_TYPE
See Also:
Constant Field Values
Constructor Detail

JSONUtil

public JSONUtil()
Method Detail

setJSONExpected

public static void setJSONExpected(org.apache.commons.httpclient.HttpMethod method)
Sets a header to notify server we expect a JSON-repsponse for this method.

Parameters:
method -

populateRequestBody

public static void populateRequestBody(org.apache.commons.httpclient.methods.EntityEnclosingMethod method,
                                       org.json.simple.JSONObject object)
Adds the JSON as request-body the the method and sets the correct content-type.

Parameters:
method -
object -

getDataFromResponse

public static org.json.simple.JSONObject getDataFromResponse(org.apache.commons.httpclient.HttpMethod method)
Extract the "data" JSON-object from the method's response.

Parameters:
method - the method containing the response
Returns:
the "data" object. Returns null if response is not JSON or no data-object is present.

getDataArrayFromResponse

public static org.json.simple.JSONArray getDataArrayFromResponse(org.apache.commons.httpclient.HttpMethod method)
Extract the "data" JSON-array from the method's response.

Parameters:
method - the method containing the response
Returns:
the "data" object. Returns null if response is not JSON or no data-object is present.

getObjectFromResponse

public static org.json.simple.JSONObject getObjectFromResponse(org.apache.commons.httpclient.HttpMethod method)
Extract JSON-object from the method's response.

Parameters:
method - the method containing the response
Returns:
the json object. Returns null if response is not JSON or no data-object is present.

getString

public static String getString(org.json.simple.JSONObject json,
                               String key,
                               String defaultValue)
Gets a string-value from the given JSON-object for the given key.

Parameters:
json - the json object
key - key pointing to the value
defaultValue - if value is not set or if value is not of type "String", this value is returned

getArray

public static org.json.simple.JSONArray getArray(org.json.simple.JSONObject json,
                                                 String key)
Parameters:
json - JSON to extract array from
key - key under which array is present on JSON
Returns:
the JSONArray. Returns null, if the value is null or not an array.

getObject

public static org.json.simple.JSONObject getObject(org.json.simple.JSONObject json,
                                                   String key)
Parameters:
json - JSON to extract object from
key - key under which object is present on JSON
Returns:
the JSONObject. Returns null, if the value is null or not an object.


Copyright © 2012. All Rights Reserved.