@@ -113,33 +113,46 @@ object Util {
113
113
}
114
114
}
115
115
116
+ fun map2StringMap (m : Map <* , * >): MutableMap <String , Any ?> {
117
+ val o = mutableMapOf<String , Any ?>()
118
+ m.forEach {
119
+ if (it.key is String ) {
120
+ o[it.key as String ] = it.value as Any
121
+ }
122
+ }
123
+ return o
124
+ }
116
125
117
- fun mergeJSON (j : String , to : MutableMap <String , Any >) {
118
- if (j.isBlank()) return
119
- val m = JavaUtil .gson.fromJson(j, to.javaClass)
120
- m.forEach { (k, v) ->
121
- if (v is Map <* , * > && to[k] is Map <* , * >) {
122
- val currentMap = (to[k] as Map <* , * >).toMutableMap()
123
- currentMap + = v
124
- to[k] = currentMap
126
+ fun mergeMap (dst : MutableMap <String , Any ?>, src : Map <String , Any ?>): MutableMap <String , Any ?> {
127
+ src.forEach { (k, v) ->
128
+ if (v is Map <* , * > && dst[k] is Map <* , * >) {
129
+ val currentMap = (dst[k] as Map <* , * >).toMutableMap()
130
+ dst[k] = mergeMap(map2StringMap(currentMap), map2StringMap(v))
125
131
} else if (v is List <* >) {
126
132
if (k.startsWith(" +" )) { // prepend
127
133
val dstKey = k.removePrefix(" +" )
128
- var currentList = (to [dstKey] as List <* >).toMutableList()
134
+ var currentList = (dst [dstKey] as List <* >).toMutableList()
129
135
currentList = (v + currentList).toMutableList()
130
- to [dstKey] = currentList
136
+ dst [dstKey] = currentList
131
137
} else if (k.endsWith(" +" )) { // append
132
138
val dstKey = k.removeSuffix(" +" )
133
- var currentList = (to [dstKey] as List <* >).toMutableList()
139
+ var currentList = (dst [dstKey] as List <* >).toMutableList()
134
140
currentList = (currentList + v).toMutableList()
135
- to [dstKey] = currentList
141
+ dst [dstKey] = currentList
136
142
} else {
137
- to [k] = v
143
+ dst [k] = v
138
144
}
139
145
} else {
140
- to [k] = v
146
+ dst [k] = v
141
147
}
142
148
}
149
+ return dst
150
+ }
151
+
152
+ fun mergeJSON (j : String , dst : MutableMap <String , Any ?>) {
153
+ if (j.isBlank()) return
154
+ val src = JavaUtil .gson.fromJson(j, dst.javaClass)
155
+ mergeMap(dst, src)
143
156
}
144
157
145
158
// Format Time
0 commit comments