mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +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.*
|
||||||
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,
|
||||||
|
@ -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
|
||||||
|
|
||||||
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