package dp.kotul.starter.util

import com.google.common.base.CaseFormat
import java.util.HashMap
import kotlin.reflect.full.memberProperties

object Serializer {
    fun objectToMap(instance: Any): MutableMap<String, Any?> {
        val fields = instance.javaClass.kotlin.memberProperties
        val result = HashMap<String, Any?>()
        for (field in fields) {
            val attributeName = field.name
            try {
                val valObject = field.get(instance)
                result[CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, attributeName)] = valObject
            } catch (e: Exception) {
                continue
            }
        }
        return result
    }
}
