KMP Serialization
Serialization
Use custom adapters when the public generated API should expose a domain type instead of the raw SQLite storage type.
CREATE TABLE task
(
id INTEGER PRIMARY KEY NOT NULL,
-- @@{ field=tags, adapter=custom, propertyType=List<String> }
tags TEXT NOT NULL
);
val db = AppDatabase(
dbName = dbPath,
migration = VersionBasedDatabaseMigrations(),
taskAdapters = AppDatabase.TaskAdapters(
sqlColumnToTags = { value -> value.jsonDecodeFromSqlite() },
tagsToSqlColumn = { tags -> tags.jsonEncodeToSqlite() },
),
)
Prefer stable serialized values for enums and timestamps. For absolute time, store RFC3339 text with an explicit zone instead of locale-specific strings.