Class JSONUtil

java.lang.Object
de.uplanet.lucy.server.auxiliaries.JSONUtil

@VelocityVariable("JSON") @VelocityCallable("singleton") public final class JSONUtil extends Object
  • Constructor Details

    • JSONUtil

      public JSONUtil()
  • Method Details

    • 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.
      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 is true 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, or false 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, or
      • null.
    • 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, or
      • null.
    • 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, or
      • null.
      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.