Class JsonBrowser
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.JsonBrowser
-
public class JsonBrowser extends java.lang.ObjectAllows to easily navigate in decoded JSON data
-
-
Field Summary
Fields Modifier and Type Field Description static JsonBrowserNULL_BROWSER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Object item)Add a value to the list if this instance contains a list.<T> Tas(com.fasterxml.jackson.core.type.TypeReference<T> type)<T> Tas(java.lang.Class<T> klass)Attempt to retrieve the value in the specified formatbooleanasBoolean(boolean defaultValue)intasInt(int defaultValue)longasLong(long defaultValue)java.lang.Stringformat()JsonBrowserget(java.lang.String key)Get an element by key from a map valueJsonBrowserindex(int index)Get an element at an index for a list valuebooleanisList()booleanisMap()booleanisNull()static JsonBrowsernewList()static JsonBrowsernewMap()static JsonBrowserparse(java.io.InputStream stream)Parse from string.static JsonBrowserparse(java.lang.String json)Parse from string.voidput(java.lang.String key, java.lang.Object item)Put a value into the map if this instance contains a map.voidremove(int index)Remove a value from the list if this instance contains a list.voidremove(java.lang.String key)Remove a value from the map if this instance contains a map.java.lang.StringsafeText()voidset(int index, java.lang.Object item)Set a value in the list if this instance contains a list.java.lang.Stringtext()java.lang.StringtextOrDefault(java.lang.String defaultValue)java.util.List<JsonBrowser>values()Returns a list of all the values in this element
-
-
-
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 keyitem- 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 indexitem- 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
-
-