Skip to content

Commit

Permalink
update more json parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisives committed Jan 31, 2024
1 parent 930b966 commit cbe183b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal open class Requests(
json: JsonObject
): com.highmobility.hmkitfleet.network.Response<T> = if (errors != null && errors.size > 0) {
val error =
Json.decodeFromJsonElement<Error>(errors.first())
jsonIg.decodeFromJsonElement<Error>(errors.first())
Response(null, error)
} else {
val error = Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit cbe183b

Please sign in to comment.