Last active
January 2, 2023 05:24
-
-
Save ravisorathiya/d736e6e29e3f9017318d3275aa7e9844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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