From 3244e5aa98977fa983526b1c80bcb03af3aab715 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 10 May 2020 02:47:10 +0200 Subject: Fix RestClient data serialization. --- src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt index f7091f96..e55249cc 100644 --- a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt +++ b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt @@ -32,6 +32,7 @@ import pl.treksoft.jquery.JQueryXHR import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.types.DateSerializer import pl.treksoft.kvision.utils.JSON +import pl.treksoft.kvision.utils.JSON.toObj import pl.treksoft.kvision.utils.obj import kotlin.js.Date import kotlin.js.Promise @@ -131,7 +132,8 @@ open class RestClient { contentType: String = "application/json", beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null ): Promise { - return remoteCall(url, JSON.plain.stringify(serializer, data), method, contentType, beforeSend) + val data = if (method == HttpMethod.GET) data.toObj(serializer) else JSON.plain.stringify(serializer, data) + return remoteCall(url, data, method, contentType, beforeSend) } @@ -157,9 +159,10 @@ open class RestClient { beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, transform: ((dynamic) -> dynamic)? = null ): Promise { + val data = if (method == HttpMethod.GET) data.toObj(serializer) else JSON.plain.stringify(serializer, data) return remoteCall( url, - JSON.plain.stringify(serializer, data), + data, method, contentType, beforeSend @@ -419,7 +422,8 @@ open class RestClient { contentType: String = "application/json", beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null ): Promise> { - return remoteRequest(url, JSON.plain.stringify(serializer, data), method, contentType, beforeSend) + val data = if (method == HttpMethod.GET) data.toObj(serializer) else JSON.plain.stringify(serializer, data) + return remoteRequest(url, data, method, contentType, beforeSend) } @@ -445,9 +449,10 @@ open class RestClient { beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, transform: ((dynamic) -> dynamic)? = null ): Promise> { + val data = if (method == HttpMethod.GET) data.toObj(serializer) else JSON.plain.stringify(serializer, data) return remoteRequest( url, - JSON.plain.stringify(serializer, data), + data, method, contentType, beforeSend -- cgit