The Kotlin SDK uses kotlinx.serialization as its data model. Payloads are sent and received as JSON, so you work with JsonElement values directly, or decode them into your own @Serializable types.
Defining serializable types
Annotate your data classes with @Serializable. Field names map directly to record fields; use @SerialName to map a different key.
Decoding query results
The inline .queryAs<T>() helper runs a query and decodes its result into T, while every fluent builder offers the typed .awaitAs<T>() terminal.
To decode an arbitrary JsonElement you already hold, use .decode<T>().
Building payloads
When writing data, build a JsonObject with buildJsonObject, or encode a serializable instance with the client's json instance.
Customising the JSON format
The json field on SurrealClientConfig lets you supply a custom Json instance, for example to register contextual serializers or change null handling. The default ignores unknown keys and is lenient.
Learn more
Value types for
Table,RecordId, and the JSON modelExecuting queries for
queryAsQuery builder reference for
awaitAskotlinx.serialization for the underlying library