Package com.glitchybyte.glib.json
Class GJsonMapNavigator
java.lang.Object
com.glitchybyte.glib.json.GJsonMapNavigator
Class to navigate a tree of maps.
Specifically designed to navigate freeform json.
A path in this class is of the following form: "first/array[2]/resource"
first is an example of traversing objects by name.
array[2] is an example of accessing a list. In this case the item at index 2.
resource is an example of the final resource you are trying to retrieve.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGJsonMapNavigator(Map<String, Object> map) Constructs aGJsonMapNavigatorfrom an already populatedMap. -
Method Summary
Modifier and TypeMethodDescriptionstatic GJsonMapNavigatorfromInputStream(InputStream stream) Creates aGJsonMapNavigatorfrom json coming from anInputStream.static GJsonMapNavigatorfromString(String json) Creates aGJsonMapNavigatorfrom a jsonString.getObjectList(String path) Retrieves theListvalue of the given path.Retrieves theStringvalue of the given path.getStringList(String path) Retrieves theListvalue of the given path.toString()
-
Field Details
-
MAP_TYPE
Type of map. Used for Gson conversions.
-
-
Constructor Details
-
GJsonMapNavigator
Constructs aGJsonMapNavigatorfrom an already populatedMap.- Parameters:
map- Map to navigate.
-
-
Method Details
-
fromInputStream
Creates aGJsonMapNavigatorfrom json coming from anInputStream.- Parameters:
stream- InputStream from which to read json.- Returns:
- A populated GJsonMapNavigator.
-
fromString
Creates aGJsonMapNavigatorfrom a jsonString.- Parameters:
json- Json string.- Returns:
- A populated GJsonMapNavigator.
-
getString
Retrieves theStringvalue of the given path.- Parameters:
path- Path to resource.- Returns:
- String value of the resource, or NULL if resource wasn't found.
-
getObjectList
Retrieves theListvalue of the given path.- Parameters:
path- Path to resource.- Returns:
- List value of the resource, or NULL if resource wasn't found.
-
getStringList
Retrieves theListvalue of the given path.- Parameters:
path- Path to resource.- Returns:
- List value of the resource, or NULL if resource wasn't found.
-
toString
-