Class GSONP

java.lang.Object
org.fastily.jwiki.util.GSONP

public class GSONP
extends Object
Static utility methods for use with Gson.
Author:
Fastily
  • Field Details

    • gson

      public static final Gson gson
      Default Gson object, for convenience.
    • gsonPP

      public static final Gson gsonPP
      Gson object which generates pretty-print (human-readable) JSON.
  • Method Details

    • getJOofJO

      public static ArrayList<JsonObject> getJOofJO​(JsonObject input)
      Convert a JsonObject of JsonObject to an ArrayList of JsonObject.
      Parameters:
      input - A JsonObject containing only other JsonObject objects.
      Returns:
      An ArrayList of JsonObject derived from input.
    • getJAofJO

      public static ArrayList<JsonObject> getJAofJO​(JsonArray input)
      Convert a JsonArray of JsonObject to an ArrayList of JsonObject.
      Parameters:
      input - A JsonArray of JsonObject.
      Returns:
      An ArrayList of JsonObject derived from input.
    • getJAofJO

      public static ArrayList<JsonObject> getJAofJO​(JsonObject input, String key)
      Get a JsonArray of JsonObject as a List of JsonObject. PRECONDITION: key points to a JsonArray of JsonObject in input
      Parameters:
      input - The source JsonObject.
      key - Points to a JsonArray of JsonObject
      Returns:
      An ArrayList of JsonObject derived from input, or an empty ArrayList if a JsonArray associated with key could not be found in input
    • pairOff

      public static HashMap<String,​String> pairOff​(ArrayList<JsonObject> input, String kk, String vk)
      Extract a pair of String values from each JsonObject in an ArrayList of JsonObject
      Parameters:
      input - The source List
      kk - Points to each key in to be used in the resulting Map.
      vk - Points to each value in to be used in the resulting Map.
      Returns:
      The pairs of String values.
    • nestedHas

      public static boolean nestedHas​(JsonObject jo, List<String> keys)
      Performs a nested JO lookup for the specified path to see if it exists.
      Parameters:
      jo - The JsonObject to check.
      keys - The key path to follow.
      Returns:
      True if the path specified by keys exists, or false otherwise.
    • getNestedJO

      public static JsonObject getNestedJO​(JsonObject input, List<String> keys)
      Attempt to get a nested JsonObject inside input.
      Parameters:
      input - The parent JsonObject
      keys - The path to follow to access the nested JsonObject.
      Returns:
      The specified JsonObject or null if it could not be found.
    • getNestedJA

      public static JsonArray getNestedJA​(JsonObject input, List<String> keys)
      Attempt to get a nested JsonArray inside input. This means that the JsonArray is the last element in a set of nested JsonObjects.
      Parameters:
      input - The parent JsonObject
      keys - The path to follow to access the nested JsonArray.
      Returns:
      The specified JsonArray or null if it could not be found.
    • getStr

      public static String getStr​(JsonObject jo, String key)
      Get a String from a JsonObject. Returns null if a value for key was not found.
      Parameters:
      jo - The JsonObject to look for key in
      key - The key to look for
      Returns:
      The value associated with key as a String, or null if the key could not be found.
    • jaOfStrToAL

      public static ArrayList<String> jaOfStrToAL​(JsonArray ja)
      Get a JsonArray of String objects as an ArrayList of String objects.
      Parameters:
      ja - The source JsonArray
      Returns:
      The ArrayList derived from ja