Skip to content
Snippets Groups Projects
Commit 686b1170 authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Updated decodeArray to handle empty arrays

parent 5d66b10c
No related branches found
No related tags found
No related merge requests found
...@@ -29,13 +29,17 @@ interface BindingsModel { ...@@ -29,13 +29,17 @@ interface BindingsModel {
} }
} }
inline fun <reified T> decodeArray(data: ByteArray?): List<T> { internal inline fun <reified T> decodeArray(data: ByteArray?): List<T> {
return data?.run { return data?.run {
if (isNotEmpty() && decodeToString() != "null") { if (isValidData()) {
val typeToken = object : TypeToken<Array<T>>() {}.type val typeToken = object : TypeToken<Array<T>>() {}.type
Gson().fromJson<Array<T>>(decodeToString(), typeToken).toList() Gson().fromJson<Array<T>>(decodeToString(), typeToken).toList()
} else listOf() } else listOf()
} ?: listOf() } ?: listOf()
} }
internal fun ByteArray.isValidData(): Boolean {
return isNotEmpty() && decodeToString() != "[]" && decodeToString() != "null"
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment