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

com.neko233.config233.reader.convert.ConfigOrmUtils.kt Maven / Gradle / Ivy

The newest version!
package com.neko233.config233.reader.convert

object ConfigOrmUtils {


    @JvmStatic
    fun  getObjByTextKvMap(
        data: Map,
        clazz: Class,
    ): T? {
        val obj = clazz.newInstance()

        for ((fieldName, value) in data) {
            val field = clazz.getDeclaredField(fieldName)
            field.isAccessible = true
            val fieldType = field.type

            val strategy = TextConvertValueStrategyFactory.instance.getStrategy(fieldType)
                ?: return null

            val convertedValue = strategy.convert(value)
            field.set(obj, convertedValue)
        }

        return obj
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy