File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
OpacityCore/src/main/java/com/opacitylabs/opacitycore Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,27 @@ object OpacityCore {
159159// return withContext(Dispatchers.IO) { getGustoPayrollAdminIdNative() }
160160// }
161161
162+ fun parseJsonElementToAny (jsonElement : JsonElement ): Any {
163+ return when (jsonElement) {
164+ is JsonPrimitive -> {
165+ when {
166+ jsonElement.isString -> jsonElement.toString()
167+ jsonElement.intOrNull != null -> jsonElement.int
168+ jsonElement.booleanOrNull != null -> jsonElement.boolean
169+ jsonElement.doubleOrNull != null -> jsonElement.double
170+ else -> throw Exception (" Could not convert JSON primitive $jsonElement " )
171+ }
172+ }
173+ is JsonObject -> {
174+ jsonElement.toMap().mapValues { parseJsonElementToAny(it.value) }
175+ }
176+ is JsonArray -> {
177+ jsonElement.map { parseJsonElementToAny(it) }
178+ }
179+ else -> throw Exception (" Could not convert JSON primitive $jsonElement " )
180+ }
181+ }
182+
162183 suspend fun get (name : String , params : Map <String , Any >? ): Map <String , Any > {
163184 return withContext(Dispatchers .IO ) {
164185 val paramsString = params?.let { Json .encodeToString(it) }
@@ -167,7 +188,8 @@ object OpacityCore {
167188 throw Exception (res.err)
168189 }
169190
170- val map: Map <String , JsonElement > = Json .parseToJsonElement(res.data!! ).jsonObject.toMap()
191+ val map: Map <String , Any > = Json .parseToJsonElement(res.data!! ).jsonObject
192+ .mapValues { parseJsonElementToAny(it.value) }
171193 map
172194 }
173195 }
You can’t perform that action at this time.
0 commit comments