commonMain.io.github.jan.supabase.serializer.KotlinXSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of supabase-kt Show documentation
Show all versions of supabase-kt Show documentation
A Kotlin Multiplatform Supabase SDK
package io.github.jan.supabase.serializer
import io.github.jan.supabase.SupabaseSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer
import kotlin.reflect.KType
/**
* A [SupabaseSerializer] that uses kotlinx.serialization
*/
class KotlinXSerializer(private val json: Json = Json) : SupabaseSerializer {
override fun encode(type: KType, value: T): String = json.encodeToString(serializer(type), value)
@Suppress("UNCHECKED_CAST")
override fun decode(type: KType, value: String): T =
json.decodeFromString(serializer(type), value) as T
}