1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 17:17:13 +00:00

fixes in KeyboardButtonPollType serialization

This commit is contained in:
InsanusMokrassar 2020-01-23 21:52:28 +06:00
parent b9e674821b
commit 9dc3e1ecc6
2 changed files with 8 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons
import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
@Serializable(KeyboardButtonSerializer::class) @Serializable(KeyboardButtonSerializer::class)
@ -53,9 +54,6 @@ internal object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
asJson is JsonObject && asJson.getPrimitiveOrNull(requestContactField) != null -> RequestContactKeyboardButton( asJson is JsonObject && asJson.getPrimitiveOrNull(requestContactField) != null -> RequestContactKeyboardButton(
asJson.getPrimitive(textField).content 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 is JsonObject && asJson.getPrimitiveOrNull(requestLocationField) != null -> RequestLocationKeyboardButton(
asJson.getPrimitive(textField).content asJson.getPrimitive(textField).content
) )

View File

@ -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) { override fun serialize(encoder: Encoder, obj: KeyboardButtonPollType) {
when (obj) { UnknownKeyboardButtonPollType.serializer().serialize(
RegularKeyboardButtonPollType -> RegularKeyboardButtonPollType.serializer().serialize(encoder, RegularKeyboardButtonPollType) encoder,
QuizKeyboardButtonPollType -> QuizKeyboardButtonPollType.serializer().serialize(encoder, QuizKeyboardButtonPollType) (obj as? UnknownKeyboardButtonPollType) ?: UnknownKeyboardButtonPollType(obj.type)
is UnknownKeyboardButtonPollType -> UnknownKeyboardButtonPollType.serializer().serialize(encoder, obj) )
}
} }
} }