diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-10 02:47:10 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-10 02:47:10 +0200 |
commit | 3244e5aa98977fa983526b1c80bcb03af3aab715 (patch) | |
tree | 029dd0067fa041e3ac4538347786ea9ddb4c60c5 /src/main/kotlin/pl/treksoft | |
parent | 6b90497dee8a4ff70615121f2ec8d0542f69364c (diff) | |
download | kvision-3244e5aa98977fa983526b1c80bcb03af3aab715.tar.gz kvision-3244e5aa98977fa983526b1c80bcb03af3aab715.tar.bz2 kvision-3244e5aa98977fa983526b1c80bcb03af3aab715.zip |
Fix RestClient data serialization.
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt | 13 |
1 files changed, 9 insertions, 4 deletions
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<dynamic> { - 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<T> { + 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<Response<dynamic>> { - 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<Response<T>> { + 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 |