Package org.fastily.jwiki.util
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 Summary
-
Method Summary
Modifier and Type Method Description static ArrayList<JsonObject>
getJAofJO(JsonArray input)
Convert a JsonArray of JsonObject to an ArrayList of JsonObject.static ArrayList<JsonObject>
getJAofJO(JsonObject input, String key)
Get a JsonArray of JsonObject as a List of JsonObject.static ArrayList<JsonObject>
getJOofJO(JsonObject input)
Convert a JsonObject of JsonObject to an ArrayList of JsonObject.static JsonArray
getNestedJA(JsonObject input, List<String> keys)
Attempt to get a nested JsonArray insideinput
.static JsonObject
getNestedJO(JsonObject input, List<String> keys)
Attempt to get a nested JsonObject insideinput
.static String
getStr(JsonObject jo, String key)
Get a String from a JsonObject.static ArrayList<String>
jaOfStrToAL(JsonArray ja)
Get a JsonArray of String objects as an ArrayList of String objects.static boolean
nestedHas(JsonObject jo, List<String> keys)
Performs a nested JO lookup for the specified path to see if it exists.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
-
Field Details
-
Method Details
-
getJOofJO
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
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
Get a JsonArray of JsonObject as a List of JsonObject. PRECONDITION:key
points to a JsonArray of JsonObject ininput
- 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 withkey
could not be found ininput
-
pairOff
Extract a pair of String values from each JsonObject in an ArrayList of JsonObject- Parameters:
input
- The source Listkk
- 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
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
Attempt to get a nested JsonObject insideinput
.- Parameters:
input
- The parent JsonObjectkeys
- The path to follow to access the nested JsonObject.- Returns:
- The specified JsonObject or null if it could not be found.
-
getNestedJA
Attempt to get a nested JsonArray insideinput
. This means that the JsonArray is the last element in a set of nested JsonObjects.- Parameters:
input
- The parent JsonObjectkeys
- The path to follow to access the nested JsonArray.- Returns:
- The specified JsonArray or null if it could not be found.
-
getStr
Get a String from a JsonObject. Returns null if a value forkey
was not found.- Parameters:
jo
- The JsonObject to look forkey
inkey
- The key to look for- Returns:
- The value associated with
key
as a String, or null if thekey
could not be found.
-
jaOfStrToAL
Get a JsonArray of String objects as an ArrayList of String objects.- Parameters:
ja
- The source JsonArray- Returns:
- The ArrayList derived from
ja
-