1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

add contextual serializer to DataRequest and Request to avoid exceptions

This commit is contained in:
InsanusMokrassar 2019-02-27 08:52:22 +08:00
parent 8997454a46
commit f1836ec238
2 changed files with 10 additions and 3 deletions

View File

@ -5,12 +5,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@Serializable(RequestSerializer::class)
interface Request<T: Any> { interface Request<T: Any> {
fun method(): String fun method(): String
fun resultSerializer(): KSerializer<T> fun resultSerializer(): KSerializer<T>
@ImplicitReflectionSerializer fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer)
fun json(): JsonObject = toJsonWithoutNulls()
} }
object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class)
fun <T : Any> StringFormat.extractResult( fun <T : Any> StringFormat.extractResult(
from: String, from: String,

View File

@ -1,5 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import kotlinx.serialization.ContextSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
@Serializable(DataRequestSerializer::class)
interface DataRequest<T: Any> : SimpleRequest<T> interface DataRequest<T: Any> : SimpleRequest<T>
object DataRequestSerializer : KSerializer<DataRequest<*>> by ContextSerializer(DataRequest::class)