aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt27
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/types/Date.kt7
2 files changed, 29 insertions, 5 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt
index 49222298..b2aae632 100644
--- a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt
@@ -25,12 +25,15 @@ import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.DynamicObjectParser
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.SerializationStrategy
+import kotlinx.serialization.modules.serializersModuleOf
import kotlinx.serialization.serializer
import pl.treksoft.jquery.JQueryAjaxSettings
import pl.treksoft.jquery.JQueryXHR
import pl.treksoft.jquery.jQuery
+import pl.treksoft.kvision.types.DateSerializer
import pl.treksoft.kvision.utils.JSON.toObj
import pl.treksoft.kvision.utils.obj
+import kotlin.js.Date
import kotlin.js.Promise
import kotlin.js.JSON as NativeJSON
@@ -103,7 +106,10 @@ open class RestClient {
} else {
result
}
- DynamicObjectParser().parse(transformed, deserializer)
+ DynamicObjectParser(context = serializersModuleOf(Date::class, DateSerializer)).parse(
+ transformed,
+ deserializer
+ )
}
}
@@ -157,7 +163,10 @@ open class RestClient {
} else {
result
}
- DynamicObjectParser().parse(transformed, deserializer)
+ DynamicObjectParser(context = serializersModuleOf(Date::class, DateSerializer)).parse(
+ transformed,
+ deserializer
+ )
}
}
@@ -381,7 +390,12 @@ open class RestClient {
} else {
result.data
}
- Response(DynamicObjectParser().parse(transformed, deserializer), result.textStatus, result.jqXHR)
+ Response(
+ DynamicObjectParser(context = serializersModuleOf(Date::class, DateSerializer)).parse(
+ transformed,
+ deserializer
+ ), result.textStatus, result.jqXHR
+ )
}
}
@@ -441,7 +455,12 @@ open class RestClient {
} else {
result.data
}
- Response(DynamicObjectParser().parse(transformed, deserializer), result.textStatus, result.jqXHR)
+ Response(
+ DynamicObjectParser(context = serializersModuleOf(Date::class, DateSerializer)).parse(
+ transformed,
+ deserializer
+ ), result.textStatus, result.jqXHR
+ )
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/types/Date.kt b/src/main/kotlin/pl/treksoft/kvision/types/Date.kt
index 4af141f7..83d20ea9 100644
--- a/src/main/kotlin/pl/treksoft/kvision/types/Date.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/types/Date.kt
@@ -69,7 +69,12 @@ object DateSerializer : KSerializer<Date> {
override val descriptor: SerialDescriptor = SerialClassDescImpl("kotlin.js.Date")
override fun deserialize(decoder: Decoder): Date {
- return decoder.decodeString().toDateF()
+ val str = decoder.decodeString()
+ return if (str.length == 10) {
+ "$str 00:00:00".toDateF()
+ } else {
+ str.toDateF()
+ }
}
override fun serialize(encoder: Encoder, obj: Date) {