Class SimpleJsonUtils


  • public abstract class SimpleJsonUtils
    extends java.lang.Object

    Utility methods for simple JSON support.

    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleJsonUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.sql.Clob arrayToClob​(org.json.simple.JSONArray array)
      SQL FUNCTION to convert a JSONArray into a CLOB.
      static org.json.simple.JSONArray readArray​(java.io.Reader reader)
      Construct a JSONArray from a Reader.
      static org.json.simple.JSONArray readArrayFromFile​(java.lang.String fileName, java.lang.String characterSetName)
      SQL FUNCTION to read a JSONArray from a File.
      static org.json.simple.JSONArray readArrayFromStream​(java.io.InputStream inputStream, java.lang.String characterSetName)
      Read a JSONArray from an InputStream.
      static org.json.simple.JSONArray readArrayFromString​(java.lang.String document)
      SQL FUNCTION to convert a JSON document string into a JSONArray.
      static org.json.simple.JSONArray readArrayFromURL​(java.lang.String urlString, java.lang.String characterSetName)
      SQL FUNCTION to read a JSONArray from an URL address.
      static org.json.simple.JSONArray toJSON​(java.sql.ResultSet rs)
      Pack a ResultSet into a JSONArray.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleJsonUtils

        public SimpleJsonUtils()
    • Method Detail

      • toJSON

        public static org.json.simple.JSONArray toJSON​(java.sql.ResultSet rs)
                                                throws java.sql.SQLException

        Pack a ResultSet into a JSONArray. This method could be called client-side on any query result from any DBMS. Each row is converted into a JSONObject whose keys are the corresponding column names from the ResultSet. Closes the ResultSet once it has been drained. Datatypes map to JSON values as follows:

        • NULL - The JSON null literal.
        • SMALLINT, INT, BIGINT - JSON integer values.
        • DOUBLE, FLOAT, REAL, DECIMAL, NUMERIC - JSON floating point values.
        • CHAR, VARCHAR, LONG VARCHAR, CLOB - JSON string values.
        • BLOB, VARCHAR FOR BIT DATA, LONG VARCHAR FOR BIT DATA - The byte array is turned into a hex string (2 hex digits per byte) and the result is returned as a JSON string.
        • All other types - Converted to JSON string values via their toString() methods.
        Throws:
        java.sql.SQLException
      • readArray

        public static org.json.simple.JSONArray readArray​(java.io.Reader reader)
                                                   throws java.sql.SQLException
        Construct a JSONArray from a Reader.
        Throws:
        java.sql.SQLException
      • readArrayFromString

        public static org.json.simple.JSONArray readArrayFromString​(java.lang.String document)
                                                             throws java.sql.SQLException

        SQL FUNCTION to convert a JSON document string into a JSONArray. This function is registered by the simpleJson optional tool.

        Throws:
        java.sql.SQLException
      • readArrayFromStream

        public static org.json.simple.JSONArray readArrayFromStream​(java.io.InputStream inputStream,
                                                                    java.lang.String characterSetName)
                                                             throws java.sql.SQLException
        Read a JSONArray from an InputStream. Close the stream after reading the JSONArray.
        Throws:
        java.sql.SQLException
      • readArrayFromFile

        public static org.json.simple.JSONArray readArrayFromFile​(java.lang.String fileName,
                                                                  java.lang.String characterSetName)
                                                           throws java.sql.SQLException
        SQL FUNCTION to read a JSONArray from a File. This function is registered by the simpleJson optional tool.
        Throws:
        java.sql.SQLException
      • readArrayFromURL

        public static org.json.simple.JSONArray readArrayFromURL​(java.lang.String urlString,
                                                                 java.lang.String characterSetName)
                                                          throws java.sql.SQLException
        SQL FUNCTION to read a JSONArray from an URL address. This function is registered by the simpleJson optional tool.
        Throws:
        java.sql.SQLException
      • arrayToClob

        public static java.sql.Clob arrayToClob​(org.json.simple.JSONArray array)
        SQL FUNCTION to convert a JSONArray into a CLOB.