Class GJsonMapNavigator

java.lang.Object
com.glitchybyte.glib.json.GJsonMapNavigator

public final class GJsonMapNavigator extends Object
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 Details

    • MAP_TYPE

      public static final Type MAP_TYPE
      Type of map. Used for Gson conversions.
  • Constructor Details

    • GJsonMapNavigator

      public GJsonMapNavigator(Map<String,Object> map)
      Constructs a GJsonMapNavigator from an already populated Map.
      Parameters:
      map - Map to navigate.
  • Method Details

    • fromInputStream

      public static GJsonMapNavigator fromInputStream(InputStream stream)
      Creates a GJsonMapNavigator from json coming from an InputStream.
      Parameters:
      stream - InputStream from which to read json.
      Returns:
      A populated GJsonMapNavigator.
    • fromString

      public static GJsonMapNavigator fromString(String json)
      Creates a GJsonMapNavigator from a json String.
      Parameters:
      json - Json string.
      Returns:
      A populated GJsonMapNavigator.
    • getString

      public String getString(String path)
      Retrieves the String value of the given path.
      Parameters:
      path - Path to resource.
      Returns:
      String value of the resource, or NULL if resource wasn't found.
    • getObjectList

      public List<Object> getObjectList(String path)
      Retrieves the List value of the given path.
      Parameters:
      path - Path to resource.
      Returns:
      List value of the resource, or NULL if resource wasn't found.
    • getStringList

      public List<String> getStringList(String path)
      Retrieves the List value of the given path.
      Parameters:
      path - Path to resource.
      Returns:
      List value of the resource, or NULL if resource wasn't found.
    • toString

      public String toString()
      Overrides:
      toString in class Object