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 StringTYPE_DATEprotected static StringTYPE_INTEGERprotected static StringTYPE_JSON_ARRAYprotected static StringTYPE_JSON_OBJECTprotected static StringTYPE_LONGprotected static StringTYPE_STRING
-
Constructor Summary
Constructors Constructor Description MyJPathUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappend(net.sf.json.JSON json, String absPath, Object newValue)static voidappend(net.sf.json.JSON json, String root, String relativePath, Object newValue)static booleancontainsKey(net.sf.json.JSON json, String absPath)static booleancontainsKey(net.sf.json.JSON json, String root, String relativePath)protected static Objectget(net.sf.json.JSON json, String absPath)static DategetDate(net.sf.json.JSON json, String absPath)static DategetDate(net.sf.json.JSON json, String root, String relativePath)static IntegergetInt(net.sf.json.JSON json, String absPath)static IntegergetInt(net.sf.json.JSON json, String root, String relativePath)protected static net.sf.json.JSONgetJSON(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.JSONArraygetJSONArray(net.sf.json.JSON json, String absPath)static net.sf.json.JSONArraygetJSONArray(net.sf.json.JSON json, String root, String relativePath)static net.sf.json.JSONObjectgetJSONObject(net.sf.json.JSON json, String absPath)static net.sf.json.JSONObjectgetJSONObject(net.sf.json.JSON json, String root, String relativePath)static LonggetLong(net.sf.json.JSON json, String absPath)static LonggetLong(net.sf.json.JSON json, String root, String relativePath)static StringgetString(net.sf.json.JSON json, String absPath)static StringgetString(net.sf.json.JSON json, String root, String relativePath)protected static intintKey(String key)static voidmain(String[] args)static voidset(net.sf.json.JSON json, String absPath, Object newValue)static voidset(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/eIt can be invoked safely ona -> b -> c -> dbut 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)
-
-