From cbe183b68938b367cc975626b6e3d34e1dacff70 Mon Sep 17 00:00:00 2001 From: tonisives Date: Wed, 31 Jan 2024 14:10:51 +0700 Subject: [PATCH] update more json parsers --- .../hmkitfleet/network/ClearanceRequests.kt | 10 +++++----- .../com/highmobility/hmkitfleet/network/Requests.kt | 2 +- .../highmobility/hmkitfleet/network/UtilityRequests.kt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/ClearanceRequests.kt b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/ClearanceRequests.kt index 7121b2a..fe64201 100644 --- a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/ClearanceRequests.kt +++ b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/ClearanceRequests.kt @@ -77,7 +77,7 @@ internal class ClearanceRequests( val response = call.await() return tryParseResponse(response, HttpURLConnection.HTTP_OK) { responseBody -> - val jsonElement = Json.parseToJsonElement(responseBody) as JsonObject + val jsonElement = jsonIg.parseToJsonElement(responseBody) as JsonObject val statuses = jsonElement["vehicles"] as JsonArray for (statusElement in statuses) { val status = @@ -108,7 +108,7 @@ internal class ClearanceRequests( val response = call.await() return tryParseResponse(response, HttpURLConnection.HTTP_OK) { responseBody -> - val statuses = Json.parseToJsonElement(responseBody) as JsonArray + val statuses = jsonIg.parseToJsonElement(responseBody) as JsonArray val builder = Array(statuses.size) { val statusElement = statuses[it] @@ -174,14 +174,14 @@ internal class ClearanceRequests( ): RequestBody { val vehicle = buildJsonObject { put("vin", vin) - put("brand", Json.encodeToJsonElement(brand)) + put("brand", jsonIg.encodeToJsonElement(brand)) if (controlMeasures != null) { putJsonObject("control_measures") { for (controlMeasure in controlMeasures) { // polymorphism adds type key to child controlmeasure classes. remove with filter - val json = Json.encodeToJsonElement(controlMeasure) + val json = jsonIg.encodeToJsonElement(controlMeasure) val valuesWithoutType = json.jsonObject.filterNot { it.key == "type" } - val jsonTrimmed = Json.encodeToJsonElement(valuesWithoutType) + val jsonTrimmed = jsonIg.encodeToJsonElement(valuesWithoutType) put("odometer", jsonTrimmed) } } diff --git a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/Requests.kt b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/Requests.kt index 192c223..1305120 100644 --- a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/Requests.kt +++ b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/Requests.kt @@ -116,7 +116,7 @@ internal open class Requests( json: JsonObject ): com.highmobility.hmkitfleet.network.Response = if (errors != null && errors.size > 0) { val error = - Json.decodeFromJsonElement(errors.first()) + jsonIg.decodeFromJsonElement(errors.first()) Response(null, error) } else { val error = Error( diff --git a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/UtilityRequests.kt b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/UtilityRequests.kt index ff45245..04e7119 100644 --- a/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/UtilityRequests.kt +++ b/hmkit-fleet/src/main/kotlin/com/highmobility/hmkitfleet/network/UtilityRequests.kt @@ -82,10 +82,10 @@ internal class UtilityRequests( ): RequestBody { val vehicle = buildJsonObject { put("vin", vin) - put("brand", Json.encodeToJsonElement(brand)) + put("brand", jsonIg.encodeToJsonElement(brand)) } - val body = Json.encodeToString(vehicle).toRequestBody(mediaType) + val body = jsonIg.encodeToString(vehicle).toRequestBody(mediaType) return body } }