Created
August 9, 2020 12:30
-
-
Save jeluchu/76eadb1417836a6635277c655c6c2fd9 to your computer and use it in GitHub Desktop.
Explain to save custom objecto on Room Database with TypeConverter
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
@TypeConverter | |
fun stringToListPromo(data: String?): List<PromoEntity?>? { | |
if (data == null) { | |
return Collections.emptyList() | |
} | |
val listType: Type = object : | |
TypeToken<List<PromoEntity?>?>() {}.type | |
return gson.fromJson<List<PromoEntity?>>(data, listType) | |
} | |
@TypeConverter | |
fun listPromoToString(someObjects: List<PromoEntity?>?): String? { | |
return gson.toJson(someObjects) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment