mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 14:40:06 +08:00
fix: mergeJSON
This commit is contained in:
parent
a65f56fa26
commit
ad61b2ee66
@ -440,7 +440,10 @@ fun buildConfig(
|
|||||||
|
|
||||||
// custom JSON merge
|
// custom JSON merge
|
||||||
if (bean.customOutboundJson.isNotBlank()) {
|
if (bean.customOutboundJson.isNotBlank()) {
|
||||||
Util.mergeJSON(bean.customOutboundJson, currentOutbound)
|
Util.mergeJSON(
|
||||||
|
bean.customOutboundJson,
|
||||||
|
currentOutbound as MutableMap<String, Any?>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -113,33 +113,46 @@ object Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun map2StringMap(m: Map<*, *>): MutableMap<String, Any?> {
|
||||||
|
val o = mutableMapOf<String, Any?>()
|
||||||
|
m.forEach {
|
||||||
|
if (it.key is String) {
|
||||||
|
o[it.key as String] = it.value as Any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
fun mergeJSON(j: String, to: MutableMap<String, Any>) {
|
fun mergeMap(dst: MutableMap<String, Any?>, src: Map<String, Any?>): MutableMap<String, Any?> {
|
||||||
if (j.isBlank()) return
|
src.forEach { (k, v) ->
|
||||||
val m = JavaUtil.gson.fromJson(j, to.javaClass)
|
if (v is Map<*, *> && dst[k] is Map<*, *>) {
|
||||||
m.forEach { (k, v) ->
|
val currentMap = (dst[k] as Map<*, *>).toMutableMap()
|
||||||
if (v is Map<*, *> && to[k] is Map<*, *>) {
|
dst[k] = mergeMap(map2StringMap(currentMap), map2StringMap(v))
|
||||||
val currentMap = (to[k] as Map<*, *>).toMutableMap()
|
|
||||||
currentMap += v
|
|
||||||
to[k] = currentMap
|
|
||||||
} else if (v is List<*>) {
|
} else if (v is List<*>) {
|
||||||
if (k.startsWith("+")) { // prepend
|
if (k.startsWith("+")) { // prepend
|
||||||
val dstKey = k.removePrefix("+")
|
val dstKey = k.removePrefix("+")
|
||||||
var currentList = (to[dstKey] as List<*>).toMutableList()
|
var currentList = (dst[dstKey] as List<*>).toMutableList()
|
||||||
currentList = (v + currentList).toMutableList()
|
currentList = (v + currentList).toMutableList()
|
||||||
to[dstKey] = currentList
|
dst[dstKey] = currentList
|
||||||
} else if (k.endsWith("+")) { // append
|
} else if (k.endsWith("+")) { // append
|
||||||
val dstKey = k.removeSuffix("+")
|
val dstKey = k.removeSuffix("+")
|
||||||
var currentList = (to[dstKey] as List<*>).toMutableList()
|
var currentList = (dst[dstKey] as List<*>).toMutableList()
|
||||||
currentList = (currentList + v).toMutableList()
|
currentList = (currentList + v).toMutableList()
|
||||||
to[dstKey] = currentList
|
dst[dstKey] = currentList
|
||||||
} else {
|
} else {
|
||||||
to[k] = v
|
dst[k] = v
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
to[k] = v
|
dst[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
fun mergeJSON(j: String, dst: MutableMap<String, Any?>) {
|
||||||
|
if (j.isBlank()) return
|
||||||
|
val src = JavaUtil.gson.fromJson(j, dst.javaClass)
|
||||||
|
mergeMap(dst, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format Time
|
// Format Time
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user