public class JsonUtilities
extends java.lang.Object
| Constructor and Description |
|---|
JsonUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static com.google.gson.JsonObject |
asJsonObject(java.lang.Object... pairs)
Convenience function for making simple name-value pair objects.
|
static com.google.gson.JsonObject |
merge(com.google.gson.JsonObject... jsonObjects)
Merge any number of
JsonObjects. |
static java.util.Optional<com.google.gson.JsonElement> |
read(com.google.gson.JsonElement json,
java.lang.String path) |
static java.util.Optional<com.google.gson.JsonArray> |
readArray(com.google.gson.JsonElement json,
java.lang.String path) |
static boolean |
readBoolean(com.google.gson.JsonElement json,
java.lang.String path,
boolean defaultValue) |
static int |
readInteger(com.google.gson.JsonElement json,
java.lang.String path,
int defaultValue)
Attempts to read an integer value from a json structure.
|
static double |
readNumber(com.google.gson.JsonElement json,
java.lang.String path,
double defaultValue)
Attempts to read a double value from a json structure.
|
static java.util.Optional<com.google.gson.JsonObject> |
readObject(com.google.gson.JsonElement json,
java.lang.String path) |
static java.lang.String |
readString(com.google.gson.JsonElement json,
java.lang.String path,
java.lang.String defaultValue)
Attempts to read a string value from a json structure.
|
public static com.google.gson.JsonObject asJsonObject(java.lang.Object... pairs)
public static java.lang.String readString(@Nullable
com.google.gson.JsonElement json,
@Nonnull
java.lang.String path,
@Nullable
java.lang.String defaultValue)
json - The json structure to search through.path - A path to what you're trying to read. Will be parsed with JsonPath.parse(String),
and will throw an IllegalArgumentException if the path is malformeddefaultValue - The value to use if anything isn't where it should be.public static double readNumber(@Nullable
com.google.gson.JsonElement json,
@Nonnull
java.lang.String path,
double defaultValue)
json - The json structure to search through.path - A path to what you're trying to read. Will be parsed with JsonPath.parse(String),
and will throw an IllegalArgumentException if the path is malformeddefaultValue - The value to use if anything isn't where it should be.public static int readInteger(@Nullable
com.google.gson.JsonElement json,
@Nonnull
java.lang.String path,
int defaultValue)
json - The json structure to search through.path - A path to what you're trying to read. Will be parsed with JsonPath.parse(String),
and will throw an IllegalArgumentException if the path is malformeddefaultValue - The value to use if anything isn't where it should be.public static boolean readBoolean(@Nullable
com.google.gson.JsonElement json,
@Nonnull
java.lang.String path,
boolean defaultValue)
public static java.util.Optional<com.google.gson.JsonObject> readObject(com.google.gson.JsonElement json,
java.lang.String path)
public static java.util.Optional<com.google.gson.JsonArray> readArray(com.google.gson.JsonElement json,
java.lang.String path)
public static java.util.Optional<com.google.gson.JsonElement> read(com.google.gson.JsonElement json,
java.lang.String path)
public static com.google.gson.JsonObject merge(com.google.gson.JsonObject... jsonObjects)
JsonObjects. Similar to Object.assign in the web world: the properties
of object n + 1 will overwrite the properties of object n where n refers to the index of the nth var arg.jsonObjects - The JsonObjects to merge. If it is null, this method will return null. If any one of the
arguments is null, it will be skipped in the merging process.