Class JsonBrowser


  • public class JsonBrowser
    extends java.lang.Object
    Allows to easily navigate in decoded JSON data
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.Object item)
      Add a value to the list if this instance contains a list.
      <T> T as​(com.fasterxml.jackson.core.type.TypeReference<T> type)  
      <T> T as​(java.lang.Class<T> klass)
      Attempt to retrieve the value in the specified format
      boolean asBoolean​(boolean defaultValue)  
      int asInt​(int defaultValue)  
      long asLong​(long defaultValue)  
      java.lang.String format()  
      JsonBrowser get​(java.lang.String key)
      Get an element by key from a map value
      JsonBrowser index​(int index)
      Get an element at an index for a list value
      boolean isList()  
      boolean isMap()  
      boolean isNull()  
      static JsonBrowser newList()  
      static JsonBrowser newMap()  
      static JsonBrowser parse​(java.io.InputStream stream)
      Parse from string.
      static JsonBrowser parse​(java.lang.String json)
      Parse from string.
      void put​(java.lang.String key, java.lang.Object item)
      Put a value into the map if this instance contains a map.
      void remove​(int index)
      Remove a value from the list if this instance contains a list.
      void remove​(java.lang.String key)
      Remove a value from the map if this instance contains a map.
      java.lang.String safeText()  
      void set​(int index, java.lang.Object item)
      Set a value in the list if this instance contains a list.
      java.lang.String text()  
      java.lang.String textOrDefault​(java.lang.String defaultValue)  
      java.util.List<JsonBrowser> values()
      Returns a list of all the values in this element
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NULL_BROWSER

        public static final JsonBrowser NULL_BROWSER
    • Method Detail

      • isList

        public boolean isList()
        Returns:
        True if the value represents a list.
      • isMap

        public boolean isMap()
        Returns:
        True if the value represents a map.
      • index

        public JsonBrowser index​(int index)
        Get an element at an index for a list value
        Parameters:
        index - List index
        Returns:
        JsonBrowser instance which wraps the value at the specified index
      • get

        public JsonBrowser get​(java.lang.String key)
        Get an element by key from a map value
        Parameters:
        key - Map key
        Returns:
        JsonBrowser instance which wraps the value with the specified key
      • put

        public void put​(java.lang.String key,
                        java.lang.Object item)
        Put a value into the map if this instance contains a map.
        Parameters:
        key - The map entry key
        item - The map entry value
      • remove

        public void remove​(java.lang.String key)
        Remove a value from the map if this instance contains a map.
        Parameters:
        key - The map entry key
      • add

        public void add​(java.lang.Object item)
        Add a value to the list if this instance contains a list.
        Parameters:
        item - The list entry value
      • set

        public void set​(int index,
                        java.lang.Object item)
        Set a value in the list if this instance contains a list.
        Parameters:
        index - The list index
        item - The list entry value
      • remove

        public void remove​(int index)
        Remove a value from the list if this instance contains a list.
        Parameters:
        index - The list index
      • values

        public java.util.List<JsonBrowser> values()
        Returns a list of all the values in this element
        Returns:
        The list of values as JsonBrowser elements
      • as

        public <T> T as​(java.lang.Class<T> klass)
        Attempt to retrieve the value in the specified format
        Parameters:
        klass - The class to retrieve the value as
        Returns:
        The value as an instance of the specified class
        Throws:
        java.lang.IllegalArgumentException - If conversion is impossible
      • as

        public <T> T as​(com.fasterxml.jackson.core.type.TypeReference<T> type)
      • text

        public java.lang.String text()
        Returns:
        The value of the element as text
      • textOrDefault

        public java.lang.String textOrDefault​(java.lang.String defaultValue)
      • asBoolean

        public boolean asBoolean​(boolean defaultValue)
      • asLong

        public long asLong​(long defaultValue)
      • asInt

        public int asInt​(int defaultValue)
      • safeText

        public java.lang.String safeText()
      • format

        public java.lang.String format()
      • isNull

        public boolean isNull()
        Returns:
        The value of the element as text
      • parse

        public static JsonBrowser parse​(java.lang.String json)
                                 throws java.io.IOException
        Parse from string.
        Parameters:
        json - The JSON object as a string
        Returns:
        JsonBrowser instance for navigating in the result
        Throws:
        java.io.IOException - When parsing the JSON failed
      • parse

        public static JsonBrowser parse​(java.io.InputStream stream)
                                 throws java.io.IOException
        Parse from string.
        Parameters:
        stream - The JSON object as a stream
        Returns:
        JsonBrowser instance for navigating in the result
        Throws:
        java.io.IOException - When parsing the JSON failed
      • newMap

        public static JsonBrowser newMap()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • newList

        public static JsonBrowser newList()
                                   throws java.io.IOException
        Throws:
        java.io.IOException