kt-telegram-bot
kt-telegram-bot copied to clipboard
Parsing InlineKeyboardMarkup object by kotlinx.serialization.json.Json causes SerializationException
I noticed that parsing InlineKeyboardMarkup
object by kotlinx.serialization.json.Json
causes SerializationException
.
Crash log:
Unknown exception: kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Cause of problem:
private val markupToString = { a: Any -> toJson(a) } // com.elbekd.bot.internal.TelegramClient
Sample:
private val markupToString = { a: Any -> kotlinx.serialization.json.Json.encodeToString(a) }
val inlineKeyboardMarkup = InlineKeyboardMarkup(listOf(listOf(
InlineKeyboardButton("Google", "https://www.google.com)
)))
val encodeToString = markupToString { inlineKeyboardMarkup } // crash!
It could be collect while sending photo:
telegramBot.sendPhoto(
ChatId.IntegerId(TELEGRAM_CHANNEL),
SendingFile(destinationFile),
"Hello world",
replyMarkup = inlineKeyboardMarkup
)
Library used:
implementation 'com.github.elbekD:kt-telegram-bot:2.1.7'
This could fix the problem:
inline fun <reified T> markupToStringV2(a: T) : String = Json.encodeToString(a)
thx. fixed in 2.1.8