Class 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. so
         getObject(obj, "/foo/bar")
     
    gets the object foo→bar. This does permit appending to an array, so if the array is at /a/b/array then
         append(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

    • Constructor Detail

      • MyJPathUtil

        public MyJPathUtil()
    • Method Detail

      • get

        protected static Object get​(net.sf.json.JSON json,
                                    String absPath)
      • 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 on a -> 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)
      • getInt

        public static Integer getInt​(net.sf.json.JSON json,
                                     String root,
                                     String relativePath)
      • getInt

        public static Integer getInt​(net.sf.json.JSON json,
                                     String absPath)
      • getLong

        public static Long getLong​(net.sf.json.JSON json,
                                   String root,
                                   String relativePath)
      • getLong

        public static Long getLong​(net.sf.json.JSON json,
                                   String absPath)
      • getString

        public static String getString​(net.sf.json.JSON json,
                                       String root,
                                       String relativePath)
      • getString

        public static String getString​(net.sf.json.JSON json,
                                       String absPath)
      • getDate

        public static Date getDate​(net.sf.json.JSON json,
                                   String root,
                                   String relativePath)
      • getDate

        public static Date getDate​(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)
      • append

        public static void append​(net.sf.json.JSON json,
                                  String absPath,
                                  Object newValue)
      • set

        public static void set​(net.sf.json.JSON json,
                               String root,
                               String relativePath,
                               Object newValue)
      • set

        public static void set​(net.sf.json.JSON json,
                               String absPath,
                               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)