Class JSONUtil
- java.lang.Object
-
- de.uplanet.lucy.server.auxiliaries.JSONUtil
-
@VelocityVariable("JSON") @VelocityCallable("singleton") public final class JSONUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSONUtil.JSONBuilder
A builder to create JSON output.
-
Constructor Summary
Constructors Constructor Description JSONUtil()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JSONUtil.JSONBuilder
createBuilder(Writer p_writer, boolean p_bAutoEnableWrite)
Create a JSON builder.de.uplanet.lucy.server.auxiliaries.net.HttpRequest
createJSONHttpRequest()
Create a JSON HTTP request object.String
escape(String p_strValue)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).org.json.simple.JSONArray
newArray()
Create a new JSON array.org.json.simple.JSONObject
newObject()
Create a new JSON object.org.json.simple.JSONObject
newObject(Map<String,?> p_map)
Create a new JSON object.Object
parse(Reader p_reader)
Parse a JSON object from a character stream.Object
parse(CharSequence p_chseq)
Parse a JSON object from a character sequence.Object
parseFromFile(String p_strPath)
Parse a JSON object from a file.String
toJSONString(Object p_value)
Convert an object to a JSON string.void
writeJSON(Writer p_writer, Object p_value)
Convert an object to a JSON string and write it to a character stream.void
writeJSONString(Object p_value, Writer p_writer)
Deprecated.UsewriteJSON(Writer, Object)
instead.
-
-
-
Method Detail
-
newObject
public org.json.simple.JSONObject newObject()
Create a new JSON object.- Returns:
- The new object.
-
newObject
public org.json.simple.JSONObject newObject(Map<String,?> p_map)
Create a new JSON object.- Parameters:
p_map
- A map that represents the JSON object.- Returns:
- The new object.
-
newArray
public org.json.simple.JSONArray newArray()
Create a new JSON array.- Returns:
- The new array.
-
escape
public String escape(String p_strValue)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).- Parameters:
p_strValue
- The string to be escaped.- Returns:
- The string with escaped characters.
-
toJSONString
public String toJSONString(Object p_value)
Convert an object to a JSON string.- Parameters:
p_value
- The object.- Returns:
- The object in JSON serialized form.
-
writeJSONString
@Deprecated public void writeJSONString(Object p_value, Writer p_writer) throws IOException
Deprecated.UsewriteJSON(Writer, Object)
instead.- Throws:
IOException
-
writeJSON
public void writeJSON(Writer p_writer, Object p_value) throws IOException
Convert an object to a JSON string and write it to a character stream.- Parameters:
p_writer
- The output stream.p_value
- The object.- Throws:
IOException
-
createBuilder
public JSONUtil.JSONBuilder createBuilder(Writer p_writer, boolean p_bAutoEnableWrite)
Create a JSON builder.This is the most flexible way to create JSON output from a variety of input data.
If the parameter
p_bAutoEnableWrite
istrue
the builder will automatically enable and disable writing on the underlying stream if the stream had previously put in the ignore-write mode.- Parameters:
p_writer
- The output stream.p_bAutoEnableWrite
-true
if the builder should manage writing on the underlying stream, orfalse
otherwise.- Returns:
- A JSON builder that writes to the given output stream.
- Since:
- Intrexx 7.0
-
parse
public Object parse(Reader p_reader)
Parse a JSON object from a character stream.- Parameters:
p_reader
- The input stream.- Returns:
- An instance of the following:
org.json.simple.JSONObject
,org.json.simple.JSONArray
,java.lang.String
,java.lang.Number
,java.lang.Boolean
, ornull
.
-
parse
public Object parse(CharSequence p_chseq)
Parse a JSON object from a character sequence.- Parameters:
p_chseq
- The text input.- Returns:
- An instance of the following:
org.json.simple.JSONObject
,org.json.simple.JSONArray
,java.lang.String
,java.lang.Number
,java.lang.Boolean
, ornull
.
-
parseFromFile
public Object parseFromFile(String p_strPath) throws IOException
Parse a JSON object from a file.- Parameters:
p_strPath
- The path to the file to be parsed.- Returns:
- An instance of the following:
org.json.simple.JSONObject
,org.json.simple.JSONArray
,java.lang.String
,java.lang.Number
,java.lang.Boolean
, ornull
.
- Throws:
IOException
- If an I/O error ocurred.
-
createJSONHttpRequest
public de.uplanet.lucy.server.auxiliaries.net.HttpRequest createJSONHttpRequest()
Create a JSON HTTP request object.- Returns:
- A JSON HTTP request object.
-
-