Class JSONNodeUtil


  • public class JSONNodeUtil
    extends Object
    Sert of static utilities for doing node surgery. Part of the issue is that the JSON library we use creates copies of things so simply getting a node and then settign values on it might not work.

    Created by Jeff Gaynor
    on 8/24/20 at 7:38 AM

    • Constructor Detail

      • JSONNodeUtil

        public JSONNodeUtil()
    • Method Detail

      • setNode

        public static void setNode​(net.sf.json.JSONObject source,
                                   String path,
                                   Object value)
        Set the value of the node for the given path.
        Parameters:
        source -
        path -
        value -
      • setNode

        public static void setNode​(net.sf.json.JSONObject source,
                                   String[] path,
                                   Object value)
        Contract is that if the path is /a/b/.../c/d then the result is node d has the given value, replacing what was there, if applicable.
        Parameters:
        source -
        path -
        value -
      • appendNode

        public static void appendNode​(net.sf.json.JSONObject source,
                                      String[] path,
                                      Object value)
        Used in the case of /a/b.../d where d is an array. This appends the value as the next element of d.
        Parameters:
        source -
        path -
        value -
      • getNextToLastNode

        public static net.sf.json.JSON getNextToLastNode​(net.sf.json.JSONObject source,
                                                         String path)
        Go to the given node and return
        Parameters:
        source -
        path - - the raw path to the node
        Returns:
      • getNextToLastNode

        public static net.sf.json.JSON getNextToLastNode​(net.sf.json.JSON j,
                                                         String[] path)
        This will return the next to last node for a pathh
        Parameters:
        j -
        path -
        Returns:
      • getNodeDropIndex

        protected static net.sf.json.JSON getNodeDropIndex​(net.sf.json.JSON j,
                                                           String[] path,
                                                           int numberOfComponentsToDrop)
      • getNode

        public static net.sf.json.JSON getNode​(net.sf.json.JSON j,
                                               String[] path)