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

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy