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

Updated decoding of empty or null JSON data



s
parent 5d66b10c
No related branches found
No related tags found
No related merge requests found
......@@ -31,11 +31,15 @@ interface BindingsModel {
inline fun <reified T> decodeArray(data: ByteArray?): List<T> {
return data?.run {
if (isNotEmpty() && decodeToString() != "null") {
if (isValidData()) {
val typeToken = object : TypeToken<Array<T>>() {}.type
Gson().fromJson<Array<T>>(decodeToString(), typeToken).toList()
} else listOf()
} ?: listOf()
}
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