From 8beb2bcc4806a69dc99acdd706f7de94bbe35955 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 13 Feb 2019 13:42:22 +0100 Subject: Unification of @Serializable -> JSON functions --- .../src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'kvision-modules/kvision-remote') diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt index 1ec5610a..e15e43cb 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt @@ -25,18 +25,15 @@ import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.DynamicObjectParser import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.json.Json import kotlinx.serialization.serializer import kotlinx.serialization.stringify import pl.treksoft.jquery.JQueryAjaxSettings import pl.treksoft.jquery.JQueryXHR import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.utils.JSON +import pl.treksoft.kvision.utils.JSON.toObj import pl.treksoft.kvision.utils.obj import kotlin.js.Promise -import kotlin.js.then -import kotlin.js.undefined -import kotlin.js.JSON as NativeJSON /** * HTTP status unauthorized (401). @@ -193,8 +190,7 @@ open class CallAgent { contentType: String = "application/json", beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null ): Promise { - val dynamicData = NativeJSON.parse(Json.stringify(serializer, data)) - return remoteCall(url, dynamicData, method, contentType, beforeSend) + return remoteCall(url, data.toObj(serializer), method, contentType, beforeSend) } @@ -220,8 +216,7 @@ open class CallAgent { beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, transform: ((dynamic) -> dynamic)? = null ): Promise { - val dynamicData = NativeJSON.parse(Json.stringify(serializer, data)) - return remoteCall(url, dynamicData, method, contentType, beforeSend).then { result: dynamic -> + return remoteCall(url, data.toObj(serializer), method, contentType, beforeSend).then { result: dynamic -> val transformed = if (transform != null) { transform(result) } else { -- cgit