commonMain.io.github.jan.supabase.serializer.JacksonSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of serializer-jackson-jvm Show documentation
Show all versions of serializer-jackson-jvm Show documentation
Extends supabase-kt with a Jackson Serializer
package io.github.jan.supabase.serializer
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.github.jan.supabase.SupabaseSerializer
import kotlin.reflect.KType
import kotlin.reflect.javaType
/**
* A [SupabaseSerializer] that uses jackson-module-kotlin
*/
class JacksonSerializer(private val mapper: ObjectMapper = jacksonObjectMapper()) : SupabaseSerializer {
override fun encode(type: KType, value: T): String = mapper.writeValueAsString(value)
@OptIn(ExperimentalStdlibApi::class)
override fun decode(type: KType, value: String): T = mapper.readValue(value, mapper.constructType(type.javaType))
}