mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 09:07:12 +00:00
fixes in KeyboardButtonPollType serialization
This commit is contained in:
parent
b9e674821b
commit
9dc3e1ecc6
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
@Serializable(KeyboardButtonSerializer::class)
|
||||
@ -53,9 +54,6 @@ internal object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
|
||||
asJson is JsonObject && asJson.getPrimitiveOrNull(requestContactField) != null -> RequestContactKeyboardButton(
|
||||
asJson.getPrimitive(textField).content
|
||||
)
|
||||
asJson is JsonObject && asJson.getPrimitiveOrNull(requestContactField) != null -> RequestContactKeyboardButton(
|
||||
asJson.getPrimitive(textField).content
|
||||
)
|
||||
asJson is JsonObject && asJson.getPrimitiveOrNull(requestLocationField) != null -> RequestLocationKeyboardButton(
|
||||
asJson.getPrimitive(textField).content
|
||||
)
|
||||
|
@ -39,11 +39,13 @@ internal object KeyboardButtonPollTypeSerializer : KSerializer<KeyboardButtonPol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Crutch due to the fact that direct serialization of objects currently does not work perfectly
|
||||
*/
|
||||
override fun serialize(encoder: Encoder, obj: KeyboardButtonPollType) {
|
||||
when (obj) {
|
||||
RegularKeyboardButtonPollType -> RegularKeyboardButtonPollType.serializer().serialize(encoder, RegularKeyboardButtonPollType)
|
||||
QuizKeyboardButtonPollType -> QuizKeyboardButtonPollType.serializer().serialize(encoder, QuizKeyboardButtonPollType)
|
||||
is UnknownKeyboardButtonPollType -> UnknownKeyboardButtonPollType.serializer().serialize(encoder, obj)
|
||||
}
|
||||
UnknownKeyboardButtonPollType.serializer().serialize(
|
||||
encoder,
|
||||
(obj as? UnknownKeyboardButtonPollType) ?: UnknownKeyboardButtonPollType(obj.type)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user