All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.github.jan.supabase.serializer.KotlinXSerializer.kt Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy