优化
This commit is contained in:
@@ -64,8 +64,8 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ruleStr.isJsonArray()) {
|
if (ruleStr.isJsonArray()) {
|
||||||
GSON.fromJsonArray<ExploreKind?>(ruleStr).getOrThrow().let {
|
GSON.fromJsonArray<ExploreKind>(ruleStr).getOrThrow().let {
|
||||||
kinds.addAll(it.filterNotNull())
|
kinds.addAll(it)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr ->
|
ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr ->
|
||||||
|
|||||||
@@ -65,10 +65,13 @@ inline fun <reified T> Gson.fromJsonArray(json: String?): Result<List<T>> {
|
|||||||
if (json == null) {
|
if (json == null) {
|
||||||
throw JsonSyntaxException("解析字符串为空")
|
throw JsonSyntaxException("解析字符串为空")
|
||||||
}
|
}
|
||||||
fromJson(
|
val type = TypeToken.getParameterized(List::class.java, T::class.java).type
|
||||||
json,
|
val list = fromJson(json, type) as List<T?>
|
||||||
TypeToken.getParameterized(List::class.java, T::class.java).type
|
if (list.contains(null)) {
|
||||||
) as List<T>
|
throw JsonSyntaxException("存在null")
|
||||||
|
}
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
list as List<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,10 +91,13 @@ inline fun <reified T> Gson.fromJsonArray(inputStream: InputStream?): Result<Lis
|
|||||||
throw JsonSyntaxException("解析流为空")
|
throw JsonSyntaxException("解析流为空")
|
||||||
}
|
}
|
||||||
val reader = InputStreamReader(inputStream)
|
val reader = InputStreamReader(inputStream)
|
||||||
fromJson(
|
val type = TypeToken.getParameterized(List::class.java, T::class.java).type
|
||||||
reader,
|
val list = fromJson(reader, type) as List<T?>
|
||||||
TypeToken.getParameterized(List::class.java, T::class.java).type
|
if (list.contains(null)) {
|
||||||
) as List<T>
|
throw JsonSyntaxException("存在null")
|
||||||
|
}
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
list as List<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +156,7 @@ class IntJsonDeserializer : JsonDeserializer<Int?> {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,6 +189,7 @@ class MapDeserializerDoubleAsIntFix :
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
json.isJsonObject -> {
|
json.isJsonObject -> {
|
||||||
val map: MutableMap<String, Any?> =
|
val map: MutableMap<String, Any?> =
|
||||||
LinkedTreeMap()
|
LinkedTreeMap()
|
||||||
@@ -193,15 +201,18 @@ class MapDeserializerDoubleAsIntFix :
|
|||||||
}
|
}
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
json.isJsonPrimitive -> {
|
json.isJsonPrimitive -> {
|
||||||
val prim = json.asJsonPrimitive
|
val prim = json.asJsonPrimitive
|
||||||
when {
|
when {
|
||||||
prim.isBoolean -> {
|
prim.isBoolean -> {
|
||||||
return prim.asBoolean
|
return prim.asBoolean
|
||||||
}
|
}
|
||||||
|
|
||||||
prim.isString -> {
|
prim.isString -> {
|
||||||
return prim.asString
|
return prim.asString
|
||||||
}
|
}
|
||||||
|
|
||||||
prim.isNumber -> {
|
prim.isNumber -> {
|
||||||
val num: Number = prim.asNumber
|
val num: Number = prim.asNumber
|
||||||
// here you can handle double int/long values
|
// here you can handle double int/long values
|
||||||
|
|||||||
Reference in New Issue
Block a user