一些优化(@NoWaterisEnough)
This commit is contained in:
@@ -74,13 +74,8 @@ inline fun <reified T> Gson.fromJsonArray(json: String?): Result<List<T>> {
|
||||
}
|
||||
val type = TypeToken.getParameterized(List::class.java, T::class.java).type
|
||||
val list = fromJson(json, type) as List<T?>
|
||||
if (list.contains(null)) {
|
||||
throw JsonSyntaxException(
|
||||
"列表不能存在null元素,可能是json格式错误,通常为列表存在多余的逗号所致"
|
||||
)
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
list as List<T>
|
||||
list.filterNotNull() as List<T>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +97,8 @@ inline fun <reified T> Gson.fromJsonArray(inputStream: InputStream?): Result<Lis
|
||||
val reader = InputStreamReader(inputStream)
|
||||
val type = TypeToken.getParameterized(List::class.java, T::class.java).type
|
||||
val list = fromJson(reader, type) as List<T?>
|
||||
if (list.contains(null)) {
|
||||
throw JsonSyntaxException(
|
||||
"列表不能存在null元素,可能是json格式错误,通常为列表存在多余的逗号所致"
|
||||
)
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
list as List<T>
|
||||
list.filterNotNull() as List<T>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user