Package net.dv8tion.jda.api.utils.data
Class DataObject
java.lang.Object
net.dv8tion.jda.api.utils.data.DataObject
- All Implemented Interfaces:
SerializableData
Represents a map of values used in communication with the Discord API.
Throws NullPointerException
,
if a parameter annotated with Nonnull
is provided with null
.
This class is not Thread-Safe.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataObject
empty()
Creates a new empty DataObject, ready to be populated with values.static DataObject
fromETF
(byte[] data) Parses usingExTermDecoder
.static DataObject
fromJson
(byte[] data) Parses a JSON payload into a DataObject instance.static DataObject
fromJson
(InputStream stream) Parses a JSON payload into a DataObject instance.static DataObject
Parses a JSON payload into a DataObject instance.static DataObject
Parses a JSON payload into a DataObject instance.Resolves any type to the provided key.Resolves a DataArray to a key.boolean
getBoolean
(String key) Resolves aBoolean
to a key.boolean
getBoolean
(String key, boolean defaultValue) Resolves aBoolean
to a key.double
Resolves a double to a key.double
Resolves a double to a key.int
Resolves an int to a key.int
Resolves an int to a key.long
Resolves a long to a key.long
Resolves a long to a key.Resolves a DataObject to a key.Resolves aString
to a key.Resolves aString
to a key.int
getUnsignedInt
(String key) Resolves an unsigned int to a key.int
getUnsignedInt
(String key, int defaultValue) Resolves an unsigned int to a key.long
getUnsignedLong
(String key) Resolves an unsigned long to a key.long
getUnsignedLong
(String key, long defaultValue) Resolves an unsigned long to a key.boolean
Whether the specified key is present.boolean
Whether the specified key is missing or nullboolean
Whether the specified key is of the specified type.keys()
Set
of all keys in this DataObject.Resolves any type to the provided key.Resolves a DataArray to a key.Resolves a DataObject to a key.Upserts a new value for the provided key.Upserts a null value for the provided key.Removes the value associated with the specified key.toData()
SerializedDataObject
for this object.byte[]
toETF()
Serializes this object as ETF MAP term.byte[]
toJson()
Serialize this object as JSON.toMap()
Converts this DataObject to aMap
toString()
values()
Collection
of all values in this DataObject.
-
Method Details
-
empty
Creates a new empty DataObject, ready to be populated with values.- Returns:
- An empty DataObject instance
- See Also:
-
fromJson
Parses a JSON payload into a DataObject instance.- Parameters:
data
- The correctly formatted JSON payload to parse- Returns:
- A DataObject instance for the provided payload
- Throws:
ParsingException
- If the provided json is incorrectly formatted
-
fromJson
Parses a JSON payload into a DataObject instance.- Parameters:
json
- The correctly formatted JSON payload to parse- Returns:
- A DataObject instance for the provided payload
- Throws:
ParsingException
- If the provided json is incorrectly formatted
-
fromJson
Parses a JSON payload into a DataObject instance.- Parameters:
stream
- The correctly formatted JSON payload to parse- Returns:
- A DataObject instance for the provided payload
- Throws:
ParsingException
- If the provided json is incorrectly formatted or an I/O error occurred
-
fromJson
Parses a JSON payload into a DataObject instance.- Parameters:
stream
- The correctly formatted JSON payload to parse- Returns:
- A DataObject instance for the provided payload
- Throws:
ParsingException
- If the provided json is incorrectly formatted or an I/O error occurred
-
fromETF
Parses usingExTermDecoder
. The provided data must start with the correct version header (131).- Parameters:
data
- The data to decode- Returns:
- A DataObject instance for the provided payload
- Throws:
IllegalArgumentException
- If the provided data is nullParsingException
- If the provided ETF payload is incorrectly formatted or an I/O error occurred- Since:
- 4.2.1
-
hasKey
Whether the specified key is present.- Parameters:
key
- The key to check- Returns:
- True, if the specified key is present
-
isNull
Whether the specified key is missing or null- Parameters:
key
- The key to check- Returns:
- True, if the specified key is null or missing
-
isType
Whether the specified key is of the specified type.- Parameters:
key
- The key to checktype
- The type to check- Returns:
- True, if the type check is successful
- See Also:
-
getObject
Resolves a DataObject to a key.- Parameters:
key
- The key to check for a value- Returns:
- The resolved instance of DataObject for the key
- Throws:
ParsingException
- If the type is incorrect or no value is present for the specified key
-
optObject
Resolves a DataObject to a key.- Parameters:
key
- The key to check for a value- Returns:
- The resolved instance of DataObject for the key, wrapped in
Optional
- Throws:
ParsingException
- If the type is incorrect
-
getArray
Resolves a DataArray to a key.- Parameters:
key
- The key to check for a value- Returns:
- The resolved instance of DataArray for the key
- Throws:
ParsingException
- If the type is incorrect or no value is present for the specified key
-
optArray
Resolves a DataArray to a key.- Parameters:
key
- The key to check for a value- Returns:
- The resolved instance of DataArray for the key, wrapped in
Optional
- Throws:
ParsingException
- If the type is incorrect
-
opt
Resolves any type to the provided key.- Parameters:
key
- The key to check for a value- Returns:
Optional
with a possible value
-
get
Resolves any type to the provided key.- Parameters:
key
- The key to check for a value- Returns:
- The value of any type
- Throws:
ParsingException
- If the value is missing or null- See Also:
-
getString
Resolves aString
to a key.- Parameters:
key
- The key to check for a value- Returns:
- The String value
- Throws:
ParsingException
- If the value is missing or null
-
getString
@Contract("_, !null -> !null") public String getString(@Nonnull String key, @Nullable String defaultValue) Resolves aString
to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The String value, or null if provided with null defaultValue
-
getBoolean
Resolves aBoolean
to a key.- Parameters:
key
- The key to check for a value- Returns:
- True, if the value is present and set to true. False if the value is missing or set to false.
- Throws:
ParsingException
- If the value is of the wrong type
-
getBoolean
Resolves aBoolean
to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- True, if the value is present and set to true. False if the value is set to false. defaultValue if it is missing.
- Throws:
ParsingException
- If the value is of the wrong type
-
getLong
Resolves a long to a key.- Parameters:
key
- The key to check for a value- Returns:
- The long value for the key
- Throws:
ParsingException
- If the value is missing, null, or of the wrong type
-
getLong
Resolves a long to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The long value for the key
- Throws:
ParsingException
- If the value is of the wrong type
-
getUnsignedLong
Resolves an unsigned long to a key.- Parameters:
key
- The key to check for a value- Returns:
- The unsigned long value for the key
- Throws:
ParsingException
- If the value is missing, null, or of the wrong type
-
getUnsignedLong
Resolves an unsigned long to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The unsigned long value for the key
- Throws:
ParsingException
- If the value is of the wrong type
-
getInt
Resolves an int to a key.- Parameters:
key
- The key to check for a value- Returns:
- The int value for the key
- Throws:
ParsingException
- If the value is missing, null, or of the wrong type
-
getInt
Resolves an int to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The int value for the key
- Throws:
ParsingException
- If the value is of the wrong type
-
getUnsignedInt
Resolves an unsigned int to a key.- Parameters:
key
- The key to check for a value- Returns:
- The unsigned int value for the key
- Throws:
ParsingException
- If the value is missing, null, or of the wrong type
-
getUnsignedInt
Resolves an unsigned int to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The unsigned int value for the key
- Throws:
ParsingException
- If the value is of the wrong type
-
getDouble
Resolves a double to a key.- Parameters:
key
- The key to check for a value- Returns:
- The double value for the key
- Throws:
ParsingException
- If the value is missing, null, or of the wrong type
-
getDouble
Resolves a double to a key.- Parameters:
key
- The key to check for a valuedefaultValue
- Alternative value to use when no value or null value is associated with the key- Returns:
- The double value for the key
- Throws:
ParsingException
- If the value is of the wrong type
-
remove
Removes the value associated with the specified key. If no value is associated with the key, this does nothing.- Parameters:
key
- The key to unlink- Returns:
- A DataObject with the removed key
-
putNull
Upserts a null value for the provided key.- Parameters:
key
- The key to upsert- Returns:
- A DataObject with the updated value
-
put
Upserts a new value for the provided key.- Parameters:
key
- The key to upsertvalue
- The new value- Returns:
- A DataObject with the updated value
-
values
Collection
of all values in this DataObject.- Returns:
Collection
for all values
-
keys
Set
of all keys in this DataObject.- Returns:
Set
of keys
-
toJson
Serialize this object as JSON.- Returns:
- byte array containing the JSON representation of this object
-
toETF
Serializes this object as ETF MAP term.- Returns:
- byte array containing the encoded ETF term
- Since:
- 4.2.1
-
toString
-
toPrettyString
-
toMap
Converts this DataObject to aMap
- Returns:
- The resulting map
-
toData
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-