Skip to content

Instantly share code, notes, and snippets.

@frestoinc
Created March 4, 2020 01:33
Show Gist options
  • Save frestoinc/aa117556cee430c26941ac9815a47b88 to your computer and use it in GitHub Desktop.
Save frestoinc/aa117556cee430c26941ac9815a47b88 to your computer and use it in GitHub Desktop.
Converter for room conversion in kotlin
class NestedConverter {
companion object {
@TypeConverter
@JvmStatic //needed
fun stringToList(data: String?): List<NestedRepo> {
if (data == null) {
return emptyList()
}
val type = object : TypeToken<List<NestedRepo>>() {}.type
return Gson().fromJson<List<NestedRepo>>(data, type)
}
@TypeConverter
@JvmStatic //needed
fun listToString(list: List<NestedRepo>): String {
return Gson().toJson(list)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment