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:
parent
8997454a46
commit
f1836ec238
@ -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,
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user