Package edu.uiuc.ncsa.security.util.json
Class MyJPathUtil
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.json.MyJPathUtil
-
public class MyJPathUtil extends Object
A utility for navigating JSON objects. You provide an absolute path or a root and a relative path. Note that arrays are treated consistently, so if /a is the path to the array, /a/0 is the zeroth element. sogetObject(obj, "/foo/bar")
gets the objectfoo→bar
. This does permit appending to an array, so if the array is at /a/b/array thenappend(json, "/a/b/array", newValue)
would append the value of newValue to the array.Created by Jeff Gaynor
on 9/9/20 at 9:25 AM
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
TYPE_DATE
protected static String
TYPE_INTEGER
protected static String
TYPE_JSON_ARRAY
protected static String
TYPE_JSON_OBJECT
protected static String
TYPE_LONG
protected static String
TYPE_STRING
-
Constructor Summary
Constructors Constructor Description MyJPathUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
append(net.sf.json.JSON json, String absPath, Object newValue)
static void
append(net.sf.json.JSON json, String root, String relativePath, Object newValue)
static boolean
containsKey(net.sf.json.JSON json, String absPath)
static boolean
containsKey(net.sf.json.JSON json, String root, String relativePath)
protected static Object
get(net.sf.json.JSON json, String absPath)
static Date
getDate(net.sf.json.JSON json, String absPath)
static Date
getDate(net.sf.json.JSON json, String root, String relativePath)
static Integer
getInt(net.sf.json.JSON json, String absPath)
static Integer
getInt(net.sf.json.JSON json, String root, String relativePath)
protected static net.sf.json.JSON
getJSON(net.sf.json.JSON current, String key)
Since the API we use is hinky about arrays and objects, this fronts the operation.static net.sf.json.JSONArray
getJSONArray(net.sf.json.JSON json, String absPath)
static net.sf.json.JSONArray
getJSONArray(net.sf.json.JSON json, String root, String relativePath)
static net.sf.json.JSONObject
getJSONObject(net.sf.json.JSON json, String absPath)
static net.sf.json.JSONObject
getJSONObject(net.sf.json.JSON json, String root, String relativePath)
static Long
getLong(net.sf.json.JSON json, String absPath)
static Long
getLong(net.sf.json.JSON json, String root, String relativePath)
static String
getString(net.sf.json.JSON json, String absPath)
static String
getString(net.sf.json.JSON json, String root, String relativePath)
protected static int
intKey(String key)
static void
main(String[] args)
static void
set(net.sf.json.JSON json, String absPath, Object newValue)
static void
set(net.sf.json.JSON json, String root, String relativePath, Object newValue)
-
-
-
Field Detail
-
TYPE_JSON_OBJECT
protected static final String TYPE_JSON_OBJECT
- See Also:
- Constant Field Values
-
TYPE_JSON_ARRAY
protected static final String TYPE_JSON_ARRAY
- See Also:
- Constant Field Values
-
TYPE_INTEGER
protected static final String TYPE_INTEGER
- See Also:
- Constant Field Values
-
TYPE_LONG
protected static final String TYPE_LONG
- See Also:
- Constant Field Values
-
TYPE_STRING
protected static final String TYPE_STRING
- See Also:
- Constant Field Values
-
TYPE_DATE
protected static final String TYPE_DATE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getJSON
protected static net.sf.json.JSON getJSON(net.sf.json.JSON current, String key)
Since the API we use is hinky about arrays and objects, this fronts the operation. Note that this is not used on terminal nodes, merely intermediate ones. So in the path/a/b/c/d/e
It can be invoked safely ona -> b -> c -> d
but e generally will require the specific type (int, long, etc.) and is not JSON.- Parameters:
current
-key
-- Returns:
-
getJSONObject
public static net.sf.json.JSONObject getJSONObject(net.sf.json.JSON json, String root, String relativePath)
-
getJSONObject
public static net.sf.json.JSONObject getJSONObject(net.sf.json.JSON json, String absPath)
-
getJSONArray
public static net.sf.json.JSONArray getJSONArray(net.sf.json.JSON json, String root, String relativePath)
-
getJSONArray
public static net.sf.json.JSONArray getJSONArray(net.sf.json.JSON json, String absPath)
-
intKey
protected static int intKey(String key)
-
append
public static void append(net.sf.json.JSON json, String root, String relativePath, Object newValue)
-
set
public static void set(net.sf.json.JSON json, String root, String relativePath, Object newValue)
-
containsKey
public static boolean containsKey(net.sf.json.JSON json, String root, String relativePath)
-
containsKey
public static boolean containsKey(net.sf.json.JSON json, String absPath)
-
main
public static void main(String[] args)
-
-