mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-04-05 01:22:29 +00:00
fixes in serialization
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
const val inputMediaFileAttachmentNameTemplate = "attach://%s"
|
||||
|
||||
@Serializable(InputMediaSerializer::class)
|
||||
interface InputMedia {
|
||||
val type: String
|
||||
val file: InputFile
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializer(InputMedia::class)
|
||||
object InputMediaSerializer : KSerializer<InputMedia> {
|
||||
override fun serialize(encoder: Encoder, obj: InputMedia) {
|
||||
when (obj) {
|
||||
is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, obj)
|
||||
is InputMediaAudio -> InputMediaAudio.serializer().serialize(encoder, obj)
|
||||
is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, obj)
|
||||
is InputMediaAnimation -> InputMediaAnimation.serializer().serialize(encoder, obj)
|
||||
is InputMediaDocument -> InputMediaDocument.serializer().serialize(encoder, obj)
|
||||
else -> throw IllegalArgumentException("Can't perform and serialize $obj")
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): InputMedia {
|
||||
throw IllegalStateException("Object can't be deserialized")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user