main.com.sceyt.chatuikit.persistence.converters.ListStringConverter.kt Maven / Gradle / Ivy
package com.sceyt.chatuikit.persistence.converters
import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
object ListStringConverter {
@TypeConverter
fun stringToObj(json: String?): List {
json ?: return emptyList()
val type = object : TypeToken>() {}.type
return Gson().fromJson(json, type)
}
@TypeConverter
fun objToString(obj: List?): String? {
if (obj == null)
return null
val gson = Gson()
val type = object : TypeToken>() {}.type
return gson.toJson(obj, type)
}
}