Package org.apache.derby.optional.api
Class SimpleJsonUtils
java.lang.Object
org.apache.derby.optional.api.SimpleJsonUtils
Utility methods for simple JSON support.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Clob
arrayToClob
(org.json.simple.JsonArray array) SQL FUNCTION to convert a JsonArray into a CLOB.static org.json.simple.JsonArray
Construct a JsonArray from a Reader.static org.json.simple.JsonArray
readArrayFromFile
(String fileName, String characterSetName) SQL FUNCTION to read a JsonArray from a File.static org.json.simple.JsonArray
readArrayFromStream
(InputStream inputStream, String characterSetName) Read a JsonArray from an InputStream.static org.json.simple.JsonArray
readArrayFromString
(String document) SQL FUNCTION to convert a JSON document string into a JsonArray.static org.json.simple.JsonArray
readArrayFromURL
(String urlString, String characterSetName) SQL FUNCTION to read a JsonArray from an URL address.static org.json.simple.JsonArray
Pack a ResultSet into a JsonArray.
-
Constructor Details
-
SimpleJsonUtils
public SimpleJsonUtils()
-
-
Method Details
-
toJSON
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:
SQLException
-
readArray
Construct a JsonArray from a Reader.- Throws:
SQLException
-
readArrayFromString
SQL FUNCTION to convert a JSON document string into a JsonArray. This function is registered by the simpleJson optional tool.
- Throws:
SQLException
-
readArrayFromStream
public static org.json.simple.JsonArray readArrayFromStream(InputStream inputStream, String characterSetName) throws SQLException Read a JsonArray from an InputStream. Close the stream after reading the JsonArray.- Throws:
SQLException
-
readArrayFromFile
public static org.json.simple.JsonArray readArrayFromFile(String fileName, String characterSetName) throws SQLException SQL FUNCTION to read a JsonArray from a File. This function is registered by the simpleJson optional tool.- Throws:
SQLException
-
readArrayFromURL
public static org.json.simple.JsonArray readArrayFromURL(String urlString, String characterSetName) throws SQLException SQL FUNCTION to read a JsonArray from an URL address. This function is registered by the simpleJson optional tool.- Throws:
SQLException
-
arrayToClob
SQL FUNCTION to convert a JsonArray into a CLOB.
-