hashmap.HashMapMapper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of port_store Show documentation
Show all versions of port_store Show documentation
The atoms of your platform
package com.hexagonkt.store.hashmap
import com.hexagonkt.helpers.filterEmpty
import com.hexagonkt.helpers.logger
import com.hexagonkt.serialization.convertToMap
import com.hexagonkt.serialization.convertToObject
import com.hexagonkt.store.Mapper
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.declaredMemberProperties
class HashMapMapper(private val type: KClass): Mapper {
override val fields: Map> by lazy {
logger.time ("REFLECT") { type.declaredMemberProperties }
.map { it.name to it }
.toMap()
}
override fun toStore(instance: T): Map =
instance.convertToMap()
.filterEmpty()
.mapKeys { it.key.toString() }
.mapValues { it.value }
@Suppress("UNCHECKED_CAST")
override fun fromStore(map: Map): T =
map.filterEmpty().convertToObject(type)
override fun fromStore(property: String, value: Any): Any =
value
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy