1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +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.json.JsonObject
@Serializable(RequestSerializer::class)
interface Request<T: Any> {
fun method(): String
fun resultSerializer(): KSerializer<T>
@ImplicitReflectionSerializer
fun json(): JsonObject = toJsonWithoutNulls()
fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer)
}
object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class)
fun <T : Any> StringFormat.extractResult(
from: String,

View File

@ -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<T: Any> : SimpleRequest<T>
@Serializable(DataRequestSerializer::class)
interface DataRequest<T: Any> : SimpleRequest<T>
object DataRequestSerializer : KSerializer<DataRequest<*>> by ContextSerializer(DataRequest::class)