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

jvmMain.dev.evo.elasticmagic.serde.jackson.JsonDeserializer.kt Maven / Gradle / Ivy

package dev.evo.elasticmagic.serde.jackson

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.ObjectMapper

import dev.evo.elasticmagic.serde.Deserializer
import dev.evo.elasticmagic.serde.StdDeserializer

object JsonDeserializer : StdDeserializer() {
    private val mapper = ObjectMapper()
    private val typeRef = object : TypeReference>() {}

    override fun objFromStringOrNull(data: String): Deserializer.ObjectCtx? {
        return try {
            ObjectCtx(mapper.readValue(data, typeRef))
        } catch (ex: JsonMappingException) {
            null
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy