Class GroovyJSON
- Since:
- Intrexx 7.0.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateFileContentBody
(Object p_obj) Create a file content body to be used as part of a multipart/form-data request.createFileContentBody
(Object p_obj, String p_strFileName, String p_strMimeType) Create a file content body to be used as part of a multipart/form-data request.createFileContentBody
(Object p_obj, String p_strFileName, String p_strMimeType, String p_strCharset) Create a file content body to be used as part of a multipart/form-data request.createJSONContentBody
(Object p_obj) Create a JSON content bodyto be used as part of a multipart/form-data request.Create a new JSON object.createJSONObject
(Map<?, ?> p_json) Create a new JSON object from the given map.createTextContentBody
(CharSequence p_chseq) Create a text content body to be used as part of a multipart/form-data request.createTextContentBody
(CharSequence p_chseq, String p_strMimeType) Create a text content body to be used as part of a multipart/form-data request.createTextContentBody
(CharSequence p_chseq, String p_strMimeType, String p_strCharset) Create a text content body to be used as part of a multipart/form-data request.escape
(CharSequence p_chseq) Escape a character sequence according to the JSON rules.Send a GET request and parse the response as JSON.Send a POST request and parse the response as JSON.Parse the given input as JSON.parse
(CharSequence p_chseq) Parse the given character sequence as JSON.parse
(javax.servlet.http.HttpServletRequest p_request) Parse the given request as JSON.Convert an object to its JSON representation.writeJSON
(Appendable p_appendable, Object p_obj) Convert an object to its JSON representation.
-
Constructor Details
-
GroovyJSON
public GroovyJSON()
-
-
Method Details
-
createJSONObject
Create a new JSON object.Note: Since Groovy maps can replace such JSON objects in most cases, this method is rarely required.
- Returns:
- The new JSON object.
-
createJSONObject
Create a new JSON object from the given map.Note: Since Groovy maps can replace such JSON objects in most cases, this method is rarely required.
- Parameters:
p_json
- The map to construct the JSON object.- Returns:
- The new JSON object.
-
parse
Parse the given character sequence as JSON.- Parameters:
p_chseq
- The character sequence.- See Also:
-
parse
Parse the given input as JSON.Note: Some of the objects returned might be implementing methods like
toJSONString()
, orwriteJSONString(Writer)
. Do not call these methods in scripts. They will be removed in future versions of this API.- Parameters:
p_reader
- The input stream.- Returns:
- An instance of the following:
,GroovyJSONObject
java.util.List
,java.lang.String
,java.lang.Number
,java.lang.Boolean
, ornull
.
-
parse
public Object parse(javax.servlet.http.HttpServletRequest p_request) throws IOException, org.json.simple.parser.ParseException Parse the given request as JSON.Note: Some of the objects returned might be implementing methods like
toJSONString()
, orwriteJSONString(Writer)
. Do not call these methods in scripts. They will be removed in future versions of this API.- Parameters:
p_request
- The request to be parsed.- Returns:
- An instance of the following:
,GroovyJSONObject
java.util.List
,java.lang.String
,java.lang.Number
,java.lang.Boolean
, ornull
.
- Throws:
IOException
- If an I/O error occurred.org.json.simple.parser.ParseException
- If the data could not be parsed.- Since:
- Intrexx 10.10.
-
httpGet
- Throws:
IOException
-
httpGet
- Throws:
IOException
-
httpGet
Send a GET request and parse the response as JSON.Valid parameters:
url
(required) - The URL,- optional properties as defined for
GroovyHttpRequestWrapper
.
- Parameters:
p_params
- The parameters.- Throws:
IOException
-
httpPost
Send a POST request and parse the response as JSON.Valid parameters:
url
(required) - The URL, either ajava.net.URL
, or ajava.net.URI
or any object that can be converted to a valid URL string.multipartFormData
a map containing the multipart content bodies,- optional properties as defined for
GroovyHttpRequestWrapper
.
- Parameters:
p_params
- The parameters.- Throws:
IOException
URISyntaxException
-
stringify
Convert an object to its JSON representation.The method mimics the JSON.stringify function as defined in the ECMAScript Language Scecification, 5.1 edition.
- Parameters:
p_obj
- The object.- Returns:
- The object's JSON representation.
-
createJSONContentBody
Create a JSON content bodyto be used as part of a multipart/form-data request.- Parameters:
p_obj
- The object to create the JSON body from.- Returns:
- A JSON content body containing the given data.
-
createTextContentBody
Create a text content body to be used as part of a multipart/form-data request.- Parameters:
p_chseq
- The text data.- Returns:
- The content body.
-
createTextContentBody
Create a text content body to be used as part of a multipart/form-data request.- Parameters:
p_chseq
- The text data.p_strMimeType
- The MIME type of the content body.- Returns:
- The content body.
-
createTextContentBody
public IGroovyJSONContentBody createTextContentBody(CharSequence p_chseq, String p_strMimeType, String p_strCharset) Create a text content body to be used as part of a multipart/form-data request.- Parameters:
p_chseq
- The text data.p_strMimeType
- The MIME type of the content body.p_strCharset
- The charset to be used.- Returns:
- The content body.
-
createFileContentBody
Create a file content body to be used as part of a multipart/form-data request.If an Intrexx file descriptor is given, the MIME type and the file name are taken from the descriptor, in all other cases the original file name is used and the MIME type is derived rom the file extension.
- Parameters:
p_obj
- The object that represents the file, either, a string, or ajava.io.File
, or ajava.nio.file.Path
, or an Intrexx file descriptor.- Returns:
- The content body.
-
createFileContentBody
public IGroovyJSONContentBody createFileContentBody(Object p_obj, String p_strFileName, String p_strMimeType) Create a file content body to be used as part of a multipart/form-data request.- Parameters:
p_obj
- The object that represents the file, either, a string, or ajava.io.File
, or ajava.nio.file.Path
, or an Intrexx file descriptor.p_strFileName
- The file name to be used.p_strMimeType
- The MIME type of the content body.- Returns:
- The content body.
-
createFileContentBody
public IGroovyJSONContentBody createFileContentBody(Object p_obj, String p_strFileName, String p_strMimeType, String p_strCharset) Create a file content body to be used as part of a multipart/form-data request.- Parameters:
p_obj
- The object that represents the file, either, a string, or ajava.io.File
, or ajava.nio.file.Path
, or an Intrexx file descriptor.p_strFileName
- The file name to be used.p_strMimeType
- The MIME type of the content body.p_strCharset
- The charset to be declared in the Content-Type header.- Returns:
- The content body.
-
writeJSON
Convert an object to its JSON representation.The method mimics the JSON.stringify function as defined in the ECMAScript Language Scecification, 5.1 edition.
- Parameters:
p_obj
- The object.- Returns:
- The object's JSON representation.
- Throws:
IOException
-
escape
Escape a character sequence according to the JSON rules.- Parameters:
p_chseq
- The character sequence to be escaped.- Returns:
- The escaped character sequence.
-