一些优化(@NoWaterisEnough)

This commit is contained in:
HapeLee
2025-10-27 19:46:41 +08:00
parent d18147d509
commit afbe56d853
10 changed files with 273 additions and 195 deletions
@@ -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>
}
}