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

com.github.frtu.kotlin.utils.io.BeanHelper.kt Maven / Gradle / Ivy

package com.github.frtu.kotlin.utils.io

/**
 * Allow to easily deserialize an object and use object.
 *
 * @author Frédéric TU
 * @since 1.1.4
 */
open class BeanHelper: ResourceHelper() {
    /**
     * Smart cast from List
     */
    fun toStringOrNull(list: List, index: Int): String? {
        val result = toStringOrNull(list[index])
        logger.debug("Fetch index:${index} with result:${result}")
        return result
    }

    /**
     * Smart cast from Map
     */
    fun  toStringOrNull(map: Map, key: T): String? {
        val result = toStringOrNull(map[key])
        logger.debug("Fetch key:${key} with result:${result}")
        return result
    }

    /**
     * Smart cast from Any
     */
    fun toStringOrNull(item: Any?): String? =
        if (item is String?) {
            item
        } else {
            null
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy