DatasyncValue

open class DatasyncValue : TreeLikeData

Represents a tree-like value stored by the Webcom datasync service within its real-time database.

This class provides methods to easily convert it to native primitive or composite types (Boolean, String, Number, Map, List) or business objects (kotlinx.serialization.Serializable-annotated classes or POJO classes).

Functions

Link copied to clipboard
open override fun <T : Any> asA(type: KClass<T>): T

Gets this value as an instance of type.

Link copied to clipboard
open override fun <T : Any> asListOf(type: KClass<T>): List<T>

Gets this value as a composite List of values of a given type.

Link copied to clipboard
open override fun <T : Any> asMapOf(type: KClass<T>): Map<String, T>

Gets this value as a composite Map of values of a given type.

Link copied to clipboard
open override fun child(index: Int): TreeLikeData

Gets the child node of this value (interpreted as a node representing a list) at a given index in the list.

open override fun child(key: String): TreeLikeData

Gets the child node of this value at a given key.

Link copied to clipboard
open override fun childOrNull(index: Int): TreeLikeData?

Gets the child node of this value (interpreted as a node representing a list) at a given index in the list.

open override fun childOrNull(key: String): TreeLikeData?

Gets the child node of this value at a given key.

Link copied to clipboard
inline fun <T : Any> converted(): T?

Convenient shortcut to convertTo, which returns null in case of failure.

Link copied to clipboard
inline fun <T : Any> convertedAsList(): List<T>?

Convenient shortcut to convertToListOf, which returns null in case of failure.

Link copied to clipboard
inline fun <T : Any> convertedAsMap(): Map<String, T>?

Convenient shortcut to convertToMapOf, which returns null in case of failure.

Link copied to clipboard
fun <T : Any> convertTo(type: KClass<T>): WebcomResult<T>

Converts this DatasyncValue to a given T type.

Link copied to clipboard
fun <T : Any> convertToListOf(type: KClass<T>): WebcomResult<List<T>>

Converts this DatasyncValue to a List of a given T type.

Link copied to clipboard
fun <T : Any> convertToMapOf(type: KClass<T>): WebcomResult<Map<String, T>>

Converts this DatasyncValue to a Map of a given T type.

Link copied to clipboard
open override fun hasChild(index: Int): Boolean

Checks if this value is a node representing a list with a child node at the given index in the list.

open override fun hasChild(key: String): Boolean

Checks if this value is a node with a child node at a given key.

Link copied to clipboard
open override fun stringify(): String

Gets a serialized representation of this value.

Link copied to clipboard
open override fun <T : Any> tryGet(convert: TreeLikeData.() -> T): T?

Attempt to convert this value using the given convert function and return the converted value if it succeeds or null if it fails.

Link copied to clipboard
fun value(): Any?

Returns this tree-like value as a combination of native primitive and composite types (Boolean, String, Number, Map, List).

Properties

Link copied to clipboard
val acknowledged: Boolean = true

Indicates whether this value has been acknowledged by the Webcom back end (true) or not (false).

Link copied to clipboard
open override val asBoolean: Boolean

Gets this value as a boolean primitive.

Link copied to clipboard
open override val asDouble: Double

Converts this value to Double.

Link copied to clipboard
open override val asInt: Int

Converts this value to Int.

Link copied to clipboard
open override val asList: List<TreeLikeData>

Gets this value as a composite List of TreeLikeData values.

Link copied to clipboard
open override val asLong: Long

Converts this value to Long.

Link copied to clipboard
open override val asMap: Map<String, TreeLikeData>

Gets this value as a composite Map of TreeLikeData values.

Link copied to clipboard
open override val asNative: Any?

Gets this value as a combination of native primitive and composite types (Boolean, String, Number, Map, List).

Link copied to clipboard
open override val asNumber: Number

Gets this value as a number primitive (Int, Long or Double).

Link copied to clipboard
open override val asString: String

Gets this value as a string primitive.

Link copied to clipboard
open override val children: List<TreeLikeData>

Gets the list of all child nodes (without their keys) of this value.

Link copied to clipboard
open override val isBoolean: Boolean

Indicates whether this value is boolean.

Link copied to clipboard
open override val isList: Boolean

Indicates whether this value is a node with child nodes, which can be interpreted as a list.

Link copied to clipboard
open override val isMap: Boolean

Indicates whether this value is a node with child nodes, which cannot be interpreted as a list.

Link copied to clipboard
open override val isNull: Boolean

Indicates whether this value exists (false if so, true otherwise).

Link copied to clipboard
open override val isNumber: Boolean

Indicates whether this value is a number (i.e. any type of Number).

Link copied to clipboard
open override val isString: Boolean

Indicates whether this value is a string.

Link copied to clipboard
open override val keys: Set<String>

Gets the list of the keys of all child nodes of this value.

Link copied to clipboard
open override val size: Int

Gets the number of child nodes of this value.