Skip to content

Instantly share code, notes, and snippets.

@jeluchu
Created August 9, 2020 12:30
Show Gist options
  • Save jeluchu/76eadb1417836a6635277c655c6c2fd9 to your computer and use it in GitHub Desktop.
Save jeluchu/76eadb1417836a6635277c655c6c2fd9 to your computer and use it in GitHub Desktop.
Explain to save custom objecto on Room Database with TypeConverter
@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