From f1836ec2386dabddb3fc69b603750c1ee3611f15 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 27 Feb 2019 08:52:22 +0800 Subject: [PATCH] add contextual serializer to DataRequest and Request to avoid exceptions --- .../TelegramBotAPI/requests/abstracts/Request.kt | 5 +++-- .../requests/send/media/base/DataRequest.kt | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/Request.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/Request.kt index 7ab7129b23..3776c1c69d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/Request.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/Request.kt @@ -5,12 +5,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls import kotlinx.serialization.* import kotlinx.serialization.json.JsonObject +@Serializable(RequestSerializer::class) interface Request { fun method(): String fun resultSerializer(): KSerializer - @ImplicitReflectionSerializer - fun json(): JsonObject = toJsonWithoutNulls() + fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer) } +object RequestSerializer : KSerializer> by ContextSerializer(Request::class) fun StringFormat.extractResult( from: String, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/base/DataRequest.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/base/DataRequest.kt index 996e3227ee..d9b3f3213b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/base/DataRequest.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/base/DataRequest.kt @@ -1,5 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import kotlinx.serialization.ContextSerializer +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable -interface DataRequest : SimpleRequest \ No newline at end of file +@Serializable(DataRequestSerializer::class) +interface DataRequest : SimpleRequest + +object DataRequestSerializer : KSerializer> by ContextSerializer(DataRequest::class) \ No newline at end of file