1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-18 07:45:27 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/Request.kt

20 lines
674 B
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
2019-01-17 02:43:51 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
2018-12-26 08:07:24 +00:00
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
interface Request<T: Any> {
fun method(): String
fun resultSerializer(): KSerializer<T>
@ImplicitReflectionSerializer
fun json(): JsonObject = toJsonWithoutNulls()
}
fun <T : Any> StringFormat.extractResult(
from: String,
dataSerializer: KSerializer<T>
): ResponseParameters<T> {
return parse(ResponseParameters.serializer(dataSerializer), from)
}