AnyValue

@Serializable(with = AnyValueSerializer)
classAnyValue


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

Valid values forAnyValue

AnyValue can encapsulateString,Boolean,Double, aList of one of these types, or aMap whose values are one of these types. The values can be arbitrarily nested (for example, a list that contains a map that contains other maps, and so on). The lists and maps can contain heterogeneous values; for example, a singleList can contain aString value, someBoolean values, and someList values. The values of aList or aMap may benull. The only exception is that a variable or field declared as[Any] in GraphQL maynot havenull values in the top-level list; however, nested lists or mapsmay contain null values.

StoringInt in anAnyValue

To store anInt value, simply convert it to aDouble and store theDouble value.

StoringLong in anAnyValue

To store aLong value, converting it to aDouble can be lossy if the value is sufficiently large (or small) to not be exactly representable byDouble. ThelargestLong value that can be stored in aDouble with its exact value is2^53 – 1 (9007199254740991). ThesmallestLong value that can be stored in aDouble 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. SeeMAX_SAFE_INTEGER andMIN_SAFE_INTEGER for more details.

Integration withkotlinx.serialization

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

Example

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

typeFoo@table{value:Any}

mutationFooInsert($value:Any){
key:foo_insert(data:{value:$value})
}

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

@Serializable
data
classFooInsertVariables(
@Serializable(with=AnyValueSerializer::class)valvalue:AnyValue?
)

Summary

Public constructors

AnyValue(value: Boolean)

Creates an instance that encapsulates the givenBoolean.

AnyValue(value: Double)

Creates an instance that encapsulates the givenDouble.

AnyValue(value: List<Any?>)

Creates an instance that encapsulates the givenList.

AnyValue(value: Map<StringAny?>)

Creates an instance that encapsulates the givenMap.

AnyValue(value: String)

Creates an instance that encapsulates the givenString.

Public functions

open operatorBoolean
equals(other: Any?)

Compares this object with another object for equality.

openInt

Calculates and returns the hash code for this object.

openString

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 thedefault serializer for the return type, as computed byserializer.

Public constructors

AnyValue

AnyValue(value: Boolean)

Creates an instance that encapsulates the givenBoolean.

AnyValue

AnyValue(value: Double)

Creates an instance that encapsulates the givenDouble.

AnyValue

AnyValue(value: List<Any?>)

Creates an instance that encapsulates the givenList.

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

This class makes adeep copy of the given list; therefore, any modifications to the list or its constituent lists or maps after this object is created will have no effect on thisAnyValue object.

AnyValue

AnyValue(value: Map<StringAny?>)

Creates an instance that encapsulates the givenMap.

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

This class makes adeep copy of the given map; therefore, any modifications to the map or its constituent lists or maps after this object is created will have no effect on thisAnyValue object.

AnyValue

AnyValue(value: String)

Creates an instance that encapsulates the givenString.

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 ofAnyValue 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 isnot 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 isnot 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 isAny it will be one ofString,Boolean,Double,List<Any?> orMap<String, Any?>. See theAnyValue 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

aSerializersModule to use during deserialization; may benull (the default) tonot use aSerializersModule to use during deserialization.

Returns
T

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

decode

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

Decodes the encapsulated value using thedefault serializer for the return type, as computed byserializer.

Returns
T

the object of typeT created by decoding the encapsulated value using thedefault serializer for the return type, as computed byserializer.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-09 UTC.