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

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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy