Skip to content

Instantly share code, notes, and snippets.

@ravisorathiya
Last active January 2, 2023 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravisorathiya/d736e6e29e3f9017318d3275aa7e9844 to your computer and use it in GitHub Desktop.
Save ravisorathiya/d736e6e29e3f9017318d3275aa7e9844 to your computer and use it in GitHub Desktop.
import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.wondersoftware.mastapp.business.datasource.cache.theme.ThemeEntity
import java.lang.reflect.Type
import java.util.*
class DataTypeConverter {
private val gson = Gson()
@TypeConverter
fun stringToList(data: String?): List<ThemeEntity> {
if (data == null) {
return Collections.emptyList()
}
val listType: Type = object : TypeToken<List<ThemeEntity?>?>() {}.type
return gson.fromJson<List<ThemeEntity>>(data, listType)
}
@TypeConverter
fun ListToString(someObjects: List<ThemeEntity?>?): String {
return gson.toJson(someObjects)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment