public class JSONUtil extends Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
JSONUtil() |
Modifier and Type | Method and Description |
---|---|
static org.json.simple.JSONArray |
getArray(org.json.simple.JSONObject json,
String key) |
static org.json.simple.JSONArray |
getDataArrayFromResponse(org.apache.http.HttpEntity method)
Extract the "data" JSON-array from the method's response.
|
static org.json.simple.JSONObject |
getDataFromResponse(org.apache.http.HttpEntity 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 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.http.client.methods.HttpPost method,
org.json.simple.JSONObject object)
Adds the JSON as request-body the the method and sets the correct content-type.
|
static org.json.simple.JSONObject |
readStream(org.apache.http.HttpEntity entity)
Parses http response stream into a
JSONObject . |
static void |
setJSONExpected(org.apache.http.client.methods.HttpPost method)
Sets a header to notify server we expect a JSON-repsponse for this method.
|
static org.apache.http.entity.StringEntity |
setMessageBody(org.json.simple.JSONObject json)
Populate HTTP message call with given content.
|
static org.apache.http.entity.StringEntity |
setMessageBody(String content)
Populate HTTP message call with given content.
|
public static final String JSON_DATA
public static final String JSON_ID
public static final String JSON_ITEMS
public static final String JSON_NAME
public static final String FORM_PROCESSOR_JSON_PERSISTED_OBJECT
public static final String MIME_TYPE_JSON
public static final String HEADER_ACCEPT
public static final String HEADER_CONTENT_TYPE
public static void setJSONExpected(org.apache.http.client.methods.HttpPost method)
public static void populateRequestBody(org.apache.http.client.methods.HttpPost method, org.json.simple.JSONObject object)
public static org.json.simple.JSONObject getDataFromResponse(org.apache.http.HttpEntity method)
method
- the method containing the responsepublic static org.json.simple.JSONArray getDataArrayFromResponse(org.apache.http.HttpEntity method)
method
- the method containing the responsepublic static String getString(org.json.simple.JSONObject json, String key, String defaultValue)
json
- the json objectkey
- key pointing to the valuedefaultValue
- if value is not set or if value is not of type "String", this value is returnedpublic static org.json.simple.JSONArray getArray(org.json.simple.JSONObject json, String key)
json
- JSON to extract array fromkey
- key under which array is present on JSONJSONArray
. Returns null, if the value is null or not an array.public static org.json.simple.JSONObject getObject(org.json.simple.JSONObject json, String key)
json
- JSON to extract object fromkey
- key under which object is present on JSONJSONObject
. Returns null, if the value is null or not an object.public static org.apache.http.entity.StringEntity setMessageBody(String content) throws UnsupportedEncodingException
content
- String contentStringEntity
content.UnsupportedEncodingException
- if unsupportedpublic static org.apache.http.entity.StringEntity setMessageBody(org.json.simple.JSONObject json) throws UnsupportedEncodingException
json
- JSONObject
contentStringEntity
content.UnsupportedEncodingException
- if unsupportedpublic static org.json.simple.JSONObject readStream(org.apache.http.HttpEntity entity)
JSONObject
.stream
- Http response entityJSONObject
responseCopyright © 2005–2019 Alfresco Software. All rights reserved.