org.radarbase.appconfig.client.ObjectMapperCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of radar-app-config-client Show documentation
Show all versions of radar-app-config-client Show documentation
Kotlin Client SDK to the radar-app-config API
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