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

org.radarbase.appconfig.client.ObjectMapperCache.kt Maven / Gradle / Ivy

There is a newer version: 0.5.2
Show newest version
package org.radarbase.appconfig.client

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.ObjectReader
import com.fasterxml.jackson.databind.ObjectWriter
import java.util.*

class ObjectMapperCache(val mapper: ObjectMapper) {
    private val readerCache = IdentityHashMap()
    private val writerCache = IdentityHashMap()

    fun readerFor(type: Class<*>): ObjectReader =
        readerCache.computeIfAbsent(type) { mapper.readerFor(type) }

    fun readerFor(type: TypeReference<*>): ObjectReader =
        readerCache.computeIfAbsent(type) { mapper.readerFor(type) }

    fun writerFor(type: Class<*>): ObjectWriter =
        writerCache.computeIfAbsent(type) { mapper.writerFor(type) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy