AnyValue

@Serializable(with = AnyValueSerializer)
class AnyValue


Represents a variable or field of the Data Connect custom scalar type Any.

Valid Values for AnyValue

AnyValue can encapsulate String, Boolean, Double, a List of one of these types, or a Map whose values are one of these types. The values can be arbitrarily nested (e.g. a list that contains a map that contains other maps, and so on. The lists and maps can contain heterogeneous values; for example, a single List can contain a String value, some Boolean values, and some List values. The values of a List or a Map may be null. The only exception is that a variable or field declared as [Any] in GraphQL may not have null values in the top-level list; however, nested lists or maps may contain null values.

Storing Int in an AnyValue

To store an Int value, simply convert it to a Double and store the Double value.

Storing Long in an AnyValue

To store a Long value, converting it to a Double can be lossy if the value is sufficiently large (or small) to not be exactly represented by Double. The largest Long value that can be stored in a Double with its exact value is 2^53 – 1 (9007199254740991). The smallest Long value that can be stored in a Double with its exact value is -(2^53 – 1) (-9007199254740991). This limitation is exactly the same in JavaScript, which does not have a native "int" or "long" type, but rather stores all numeric values in a 64-bit floating point value. See MAX_SAFE_INTEGER and MIN_SAFE_INTEGER for more details.

Integration with kotlinx.serialization

To serialize a value of this type when using Data Connect, use AnyValueSerializer.

Example

For example, suppose this schema and operation is defined in the GraphQL source:

type Foo @table { value: Any }
mutation FooInsert($value: Any) {
key: foo_insert(data: { value: $value })
}

then a serializable "Variables" type could be defined as follows:

@Serializable
data
class FooInsertVariables(
@Serializable(with=AnyValueSerializer::class) val value: AnyValue?
)

Summary

Public constructors

AnyValue(value: Boolean)

Creates an instance that encapsulates the given Boolean.

AnyValue(value: Double)

Creates an instance that encapsulates the given Double.

AnyValue(value: List<Any?>)

Creates an instance that encapsulates the given List.

AnyValue(value: Map<StringAny?>)

Creates an instance that encapsulates the given Map.

AnyValue(value: String)

Creates an instance that encapsulates the given String.

Public functions

open operator Boolean
equals(other: Any?)

Compares this object with another object for equality.

open Int

Calculates and returns the hash code for this object.

open String

Returns a string representation of this object, useful for debugging.

Public properties

Any

The native Kotlin type of the value encapsulated in this object.

Extension functions

T
<T : Any?> AnyValue.decode(
    deserializer: DeserializationStrategy<T>,
    serializersModule: SerializersModule?
)

Decodes the encapsulated value using the given deserializer.

inline T
<T : Any?> AnyValue.decode()

Decodes the encapsulated value using the default serializer for the return type, as computed by serializer.

Public constructors

AnyValue

AnyValue(value: Boolean)

Creates an instance that encapsulates the given Boolean.

AnyValue

AnyValue(value: Double)

Creates an instance that encapsulates the given Double.

AnyValue

AnyValue(value: List<Any?>)

Creates an instance that encapsulates the given List.

An exception is thrown if any of the values of the list, or its sub-values, are invalid for being stored in AnyValue; see the AnyValue class documentation for a detailed description of value values.

This class makes a copy of the given list; therefore, any modifications to the list after this object is created will have no effect on this AnyValue object.

AnyValue

AnyValue(value: Map<StringAny?>)

Creates an instance that encapsulates the given Map.

An exception is thrown if any of the values of the map, or its sub-values, are invalid for being stored in AnyValue; see the AnyValue class documentation for a detailed description of value values.

This class makes a copy of the given map; therefore, any modifications to the map after this object is created will have no effect on this AnyValue object.

AnyValue

AnyValue(value: String)

Creates an instance that encapsulates the given String.

Public functions

equals

open operator fun equals(other: Any?): Boolean

Compares this object with another object for equality.

Parameters
other: Any?

The object to compare to this for equality.

Returns
Boolean

true if, and only if, the other object is an instance of AnyValue whose encapsulated value compares equal using the == operator to the given object.

hashCode

open fun hashCode(): Int

Calculates and returns the hash code for this object.

The hash code is not guaranteed to be stable across application restarts.

Returns
Int

the hash code for this object, calculated from the encapsulated value.

toString

open fun toString(): String

Returns a string representation of this object, useful for debugging.

The string representation is not guaranteed to be stable and may change without notice at any time. Therefore, the only recommended usage of the returned string is debugging and/or logging. Namely, parsing the returned string or storing the returned string in non-volatile storage should generally be avoided in order to be robust in case that the string representation changes.

Returns
String

a string representation of this object's encapsulated value.

Public properties

value

val valueAny

The native Kotlin type of the value encapsulated in this object.

Although this type is Any it will be one of String, Boolean, Double, Listor Map`. See the AnyValue class documentation for a detailed description of the types of values that are supported.

Extension functions

decode

fun <T : Any?> AnyValue.decode(
    deserializer: DeserializationStrategy<T>,
    serializersModule: SerializersModule? = null
): T

Decodes the encapsulated value using the given deserializer.

Parameters
deserializer: DeserializationStrategy<T>

The deserializer for the decoder to use.

serializersModule: SerializersModule? = null

a SerializersModule to use during deserialization; may be null (the default) to not use a SerializersModule to use during deserialization.

Returns
T

the object of type T created by decoding the encapsulated value using the given deserializer.

decode

inline fun <T : Any?> AnyValue.decode(): T

Decodes the encapsulated value using the default serializer for the return type, as computed by serializer.

Returns
T

the object of type T created by decoding the encapsulated value using the default serializer for the return type, as computed by serializer.