Created
March 4, 2020 01:33
-
-
Save frestoinc/aa117556cee430c26941ac9815a47b88 to your computer and use it in GitHub Desktop.
Converter for room conversion in kotlin
This file contains hidden or 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
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