mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 12:08:43 +00:00
fixes in InlineKeyboardButtonSerializer
This commit is contained in:
parent
31f7c7f31b
commit
1cb0e096be
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.CallbackGame
|
import com.github.insanusmokrassar.TelegramBotAPI.types.games.CallbackGame
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
@Serializable(InlineKeyboardButtonSerializer::class)
|
@Serializable(InlineKeyboardButtonSerializer::class)
|
||||||
@ -14,7 +15,7 @@ sealed class InlineKeyboardButton {
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class UnknownInlineKeyboardButton internal constructor(
|
data class UnknownInlineKeyboardButton internal constructor(
|
||||||
override val text: String,
|
override val text: String,
|
||||||
val rawData: JsonObject
|
val rawData: JsonElement
|
||||||
) : InlineKeyboardButton()
|
) : InlineKeyboardButton()
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -25,11 +25,11 @@ internal object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButto
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun deserialize(decoder: Decoder): InlineKeyboardButton {
|
override fun deserialize(decoder: Decoder): InlineKeyboardButton {
|
||||||
val json = JsonObjectSerializer.deserialize(decoder)
|
val json = JsonElementSerializer.deserialize(decoder)
|
||||||
|
|
||||||
return resolveSerializer(json) ?.let {
|
return (json as? JsonObject) ?.let { resolveSerializer(it) } ?.let {
|
||||||
nonstrictJsonFormat.fromJson(it, json)
|
nonstrictJsonFormat.fromJson(it, json)
|
||||||
} ?: UnknownInlineKeyboardButton(json[textField] ?.contentOrNull ?: "", json)
|
} ?: UnknownInlineKeyboardButton("", json)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: InlineKeyboardButton) {
|
override fun serialize(encoder: Encoder, value: InlineKeyboardButton) {
|
||||||
|
Loading…
Reference in New Issue
Block a user