Package net.dv8tion.jda.api.utils.data
Class DataPath
java.lang.Object
net.dv8tion.jda.api.utils.data.DataPath
This utility class can be used to access nested values within
DataObjects
and DataArrays
.
Path Expression Grammar
The syntax for paths is given by this grammar:
<name-syntax> ::= /[^.\[\]]+/;
<index-syntax> ::= "[" <number> "]";
<name> ::= <name-syntax> | <name-syntax> "?";
<index> ::= <index-syntax> | <index-syntax> "?";
<element> ::= <name> ( <index> )*;
<path-start> ::= <element> | <index> ( <index> )*;
<path> ::= <path-start> ( "." <element> )*;
Examples
Given a JSON object such as:
{
"array": [{
"foo": "bar",
}]
}
The content of "foo"
can be accessed using the code:
String foo = DataPath.getString(root, "array[0].foo")
With the safe-access operator "?"
, you can also allow missing values within your path:
String foo = DataPath.getString(root, "array[1]?.foo", "default")
This will result in foo == "default"
, since the array element 1 is marked as optional, and missing in the actual object.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
get
(DataArray root, String path, BiFunction<DataObject, String, ? extends T> fromObject, BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpath
and finds the appropriate value within thisDataArray
.static <T> T
get
(DataObject root, String path, BiFunction<DataObject, String, ? extends T> fromObject, BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpath
and finds the appropriate value within thisDataObject
.static DataArray
Parses the givenpath
and finds the appropriate value within thisDataArray
.static DataArray
getArray
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static boolean
getBoolean
(DataArray root, String path) Parses the givenpath
and finds the appropriate value within thisDataArray
.static boolean
getBoolean
(DataArray root, String path, boolean fallback) Parses the givenpath
and finds the appropriate value within thisDataArray
.static boolean
getBoolean
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static boolean
getBoolean
(DataObject root, String path, boolean fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static double
Parses the givenpath
and finds the appropriate value within thisDataArray
.static double
Parses the givenpath
and finds the appropriate value within thisDataArray
.static double
getDouble
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static double
getDouble
(DataObject root, String path, double fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static int
Parses the givenpath
and finds the appropriate value within thisDataArray
.static int
Parses the givenpath
and finds the appropriate value within thisDataArray
.static int
getInt
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static int
getInt
(DataObject root, String path, int fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static long
Parses the givenpath
and finds the appropriate value within thisDataArray
.static long
Parses the givenpath
and finds the appropriate value within thisDataArray
.static long
getLong
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static long
getLong
(DataObject root, String path, long fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static DataObject
Parses the givenpath
and finds the appropriate value within thisDataArray
.static DataObject
getObject
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static String
Parses the givenpath
and finds the appropriate value within thisDataArray
.static String
Parses the givenpath
and finds the appropriate value within thisDataArray
.static String
getString
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static String
getString
(DataObject root, String path, String fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static int
getUnsignedInt
(DataArray root, String path) Parses the givenpath
and finds the appropriate value within thisDataArray
.static int
getUnsignedInt
(DataArray root, String path, int fallback) Parses the givenpath
and finds the appropriate value within thisDataArray
.static int
getUnsignedInt
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static int
getUnsignedInt
(DataObject root, String path, int fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static long
getUnsignedLong
(DataArray root, String path) Parses the givenpath
and finds the appropriate value within thisDataArray
.static long
getUnsignedLong
(DataArray root, String path, long fallback) Parses the givenpath
and finds the appropriate value within thisDataArray
.static long
getUnsignedLong
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static long
getUnsignedLong
(DataObject root, String path, long fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.static DataArray
Parses the givenpath
and finds the appropriate value within thisDataArray
.static DataArray
optArray
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.static DataObject
Parses the givenpath
and finds the appropriate value within thisDataArray
.static DataObject
optObject
(DataObject root, String path) Parses the givenpath
and finds the appropriate value within thisDataObject
.
-
Constructor Details
-
DataPath
public DataPath()
-
-
Method Details
-
get
@UnknownNullability public static <T> T get(@Nonnull DataObject root, @Nonnull String path, @Nonnull BiFunction<DataObject, String, ? extends T> fromObject, @Nonnull BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpath
and finds the appropriate value within thisDataObject
.- Type Parameters:
T
- The result type- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.fromObject
- Object relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataObject
where you get the value from, and the second is the field name. An example would be(obj, name) -> obj.getString(name)
or as a method referenceDataObject::getString
.fromArray
- Array relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataArray
where you get the value from, and the second is the field index. An example would be(array, index) -> obj.getString(index)
or as a method referenceDataArray::getString
.- Returns:
- The value at the provided path, using the provided resolver functions. Possibly null, if the path ends with a "?" operator, or the resolver function returns null.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
get
@UnknownNullability public static <T> T get(@Nonnull DataArray root, @Nonnull String path, @Nonnull BiFunction<DataObject, String, ? extends T> fromObject, @Nonnull BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpath
and finds the appropriate value within thisDataArray
.- Type Parameters:
T
- The result type- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.fromObject
- Object relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataObject
where you get the value from, and the second is the field name. An example would be(obj, name) -> obj.getString(name)
or as a method referenceDataObject::getString
.fromArray
- Array relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataArray
where you get the value from, and the second is the field index. An example would be(array, index) -> obj.getString(index)
or as a method referenceDataArray::getString
.- Returns:
- The value at the provided path, using the provided resolver functions. Possibly null, if the path ends with a "?" operator, or the resolver function returns null.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getBoolean
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The boolean value at the given path, if declared as optional this returns false when the value is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getBoolean
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The boolean value at the given path, if declared as optional this returns the provided fallback when the value is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getBoolean
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The boolean value at the given path, if declared as optional this returns false when the value is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getBoolean
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The boolean value at the given path, if declared as optional this returns the provided fallback when the value is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getInt
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The int value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getInt
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getInt
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The int value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getInt
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The unsigned int value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The unsigned int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The unsigned int value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The unsigned int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getLong
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingLong.parseLong(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The long value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getLong
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingLong.parseLong(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getLong
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingLong.parseLong(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The long value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getLong
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingLong.parseLong(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The unsigned long value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The unsigned long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The unsigned long value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The unsigned long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getDouble
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The double value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getDouble
Parses the givenpath
and finds the appropriate value within thisDataObject
.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String)
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The double value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getDouble
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The double value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getDouble
Parses the givenpath
and finds the appropriate value within thisDataArray
.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String)
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The double value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getString
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The String value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getString
@Contract("_, _, !null -> !null") public static String getString(@Nonnull DataObject root, @Nonnull String path, @Nullable String fallback) Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The String value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getString
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The String value at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getString
@Contract("_, _, !null -> !null") public static String getString(@Nonnull DataArray root, @Nonnull String path, @Nullable String fallback) Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The String value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getObject
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The DataObject at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
optObject
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The DataObject at the given path, or null if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getObject
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The DataObject at the given path
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
optObject
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The DataObject at the given path, or null if the path resolves to an optional value that is missing.
- Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getArray
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The
DataArray
at the given path - Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
optArray
Parses the givenpath
and finds the appropriate value within thisDataObject
.- Parameters:
root
- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with a name element, such as"foo"
.- Returns:
- The
DataArray
at the given path, or null if the path resolves to an optional value that is missing. - Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
getArray
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The
DataArray
at the given path - Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-
optArray
Parses the givenpath
and finds the appropriate value within thisDataArray
.- Parameters:
root
- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path
- The path of the value, in accordance with the described grammar byDataPath
. This must start with an index element, such as"[0]"
.- Returns:
- The
DataArray
at the given path, or null if the path resolves to an optional value that is missing. - Throws:
ParsingException
- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException
- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException
- If null is provided or the path is empty
-