public class JsonUtils
extends java.lang.Object
| Constructor and Description |
|---|
JsonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
getBoolean(com.google.gson.JsonElement element,
java.lang.String key)
Get a boolean value from a json element.
|
static boolean |
getBoolean(com.google.gson.JsonObject object,
java.lang.String key)
Get a boolean value from a json object.
|
static boolean |
getBoolean(com.google.gson.JsonObject object,
java.lang.String key,
boolean fallback)
Get a boolean value from a json object with a default value.
|
static int |
getInt(com.google.gson.JsonElement element,
java.lang.String key)
Get a int value from a json element.
|
static int |
getInt(com.google.gson.JsonObject object,
java.lang.String key)
Get a int value from a json object.
|
static int |
getInt(com.google.gson.JsonObject object,
java.lang.String key,
int fallback)
Get a int value from a json object with a default value.
|
static com.google.gson.JsonObject |
getJsonObject(com.google.gson.JsonElement element,
java.lang.String key)
Get a json object value from a json element.
|
static com.google.gson.JsonObject |
getJsonObject(com.google.gson.JsonObject object,
java.lang.String key)
Get a json object value from a json object.
|
static java.lang.String |
getString(com.google.gson.JsonElement element,
java.lang.String key)
Get a string value from a json element.
|
static java.lang.String |
getString(com.google.gson.JsonObject object,
java.lang.String key)
Get a string value from a json object.
|
static java.lang.String |
getString(com.google.gson.JsonObject object,
java.lang.String key,
java.lang.String fallback)
Get a string value from a json object with a default value.
|
static com.google.gson.JsonElement |
sort(com.google.gson.JsonElement element,
java.util.Comparator<java.lang.String> comparator)
Sort a json element.
|
static java.lang.String |
toSortedString(com.google.gson.JsonElement element,
java.util.Comparator<java.lang.String> comparator)
Convert a json element to a sorted string.
If the comparator is null, Comparator.naturalOrder() will be used. |
public static boolean getBoolean(com.google.gson.JsonElement element,
java.lang.String key)
element - The element to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive booleanpublic static boolean getBoolean(com.google.gson.JsonObject object,
java.lang.String key)
object - The object to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the json object does not contain the key or the value is not a json primitive booleanpublic static boolean getBoolean(com.google.gson.JsonObject object,
java.lang.String key,
boolean fallback)
object - The object to get the value fromkey - The key of the valuefallback - The default valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive booleanpublic static int getInt(com.google.gson.JsonElement element,
java.lang.String key)
element - The element to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive intpublic static int getInt(com.google.gson.JsonObject object,
java.lang.String key)
object - The object to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the json object does not contain the key or the value is not a json primitive intpublic static int getInt(com.google.gson.JsonObject object,
java.lang.String key,
int fallback)
object - The object to get the value fromkey - The key of the valuefallback - The default valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive intpublic static java.lang.String getString(com.google.gson.JsonElement element,
java.lang.String key)
element - The element to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive stringpublic static java.lang.String getString(com.google.gson.JsonObject object,
java.lang.String key)
object - The object to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the json object does not contain the key or the value is not a json primitive stringpublic static java.lang.String getString(com.google.gson.JsonObject object,
java.lang.String key,
java.lang.String fallback)
object - The object to get the value fromkey - The key of the valuefallback - The default valuecom.google.gson.JsonSyntaxException - If the value is not a json primitive stringpublic static com.google.gson.JsonObject getJsonObject(com.google.gson.JsonElement element,
java.lang.String key)
element - The element to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the value is not a json objectpublic static com.google.gson.JsonObject getJsonObject(com.google.gson.JsonObject object,
java.lang.String key)
object - The object to get the value fromkey - The key of the valuecom.google.gson.JsonSyntaxException - If the json object does not contain the key or the value is not a json objectpublic static java.lang.String toSortedString(@Nullable
com.google.gson.JsonElement element,
@Nullable
java.util.Comparator<java.lang.String> comparator)
comparator is null, Comparator.naturalOrder() will be used.element - The element to convertcomparator - The comparator to usepublic static com.google.gson.JsonElement sort(@Nullable
com.google.gson.JsonElement element,
@Nonnull
java.util.Comparator<java.lang.String> comparator)
element - The element to sortcomparator - The comparator to use