mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
fix of serialization issues
This commit is contained in:
parent
c40e857a23
commit
68712b49e2
@ -2,8 +2,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import java.io.File
|
||||
|
||||
@Serializable(InputFileSerializer::class)
|
||||
sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
@ -12,16 +14,17 @@ sealed class InputFile {
|
||||
/**
|
||||
* Contains file id or file url
|
||||
*/
|
||||
@Serializable(FileIdSerializer::class)
|
||||
@Serializable(InputFileSerializer::class)
|
||||
data class FileId(
|
||||
override val fileId: String
|
||||
) : InputFile()
|
||||
|
||||
fun String.toInputFile(): InputFile = FileId(this)
|
||||
|
||||
@Serializer(FileId::class)
|
||||
object FileIdSerializer : KSerializer<FileId> {
|
||||
override fun serialize(encoder: Encoder, obj: FileId) = encoder.encodeString(obj.fileId)
|
||||
@Serializer(InputFile::class)
|
||||
object InputFileSerializer : KSerializer<InputFile> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
}
|
||||
|
||||
@ -29,7 +32,7 @@ object FileIdSerializer : KSerializer<FileId> {
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
*/
|
||||
@Serializable
|
||||
@Serializable(InputFileSerializer::class)
|
||||
data class MultipartFile (
|
||||
val file: StorageFile,
|
||||
val mimeType: String = file.contentType,
|
||||
|
@ -13,11 +13,10 @@ import kotlinx.serialization.json.JsonObject
|
||||
data class SetChatPhoto (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@Transient
|
||||
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
|
||||
): ChatRequest, MultipartRequest<Boolean> {
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = this.toJson(serializer())
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ const val certificateField = "certificate"
|
||||
const val pointField = "point"
|
||||
const val xShiftField = "x_shift"
|
||||
const val yShiftField = "y_shift"
|
||||
const val scaleField = "y_shift"
|
||||
const val scaleField = "scale"
|
||||
|
||||
|
||||
const val currencyField = "currency"
|
||||
|
@ -3,11 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQue
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||
|
||||
@Serializer(InlineQueryResult::class)
|
||||
object InlineQueryResultSerializer :
|
||||
KSerializer<InlineQueryResult> {
|
||||
object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InlineQueryResult::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InlineQueryResult) {
|
||||
when(obj) {
|
||||
is InlineQueryResultArticle -> InlineQueryResultArticle.serializer().serialize(encoder, obj)
|
||||
|
@ -3,9 +3,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InputMessageContent.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.InputMessageContent
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(InputMessageContent::class)
|
||||
object InputMessageContentSerializer : KSerializer<InputMessageContent> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMessageContent::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputMessageContent) {
|
||||
when (obj) {
|
||||
is InputContactMessageContent -> InputContactMessageContent.serializer().serialize(encoder, obj)
|
||||
|
@ -9,7 +9,6 @@ import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaAudio(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(InputMedia::class)
|
||||
object InputMediaSerializer : KSerializer<InputMedia> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMedia::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputMedia) {
|
||||
when (obj) {
|
||||
is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, obj)
|
||||
|
@ -1,13 +1,19 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(MediaGroupMemberInputMedia::class)
|
||||
object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(MediaGroupMemberInputMedia::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: MediaGroupMemberInputMedia) {
|
||||
when (obj) {
|
||||
is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, obj)
|
||||
is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): MediaGroupMemberInputMedia {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(KeyboardMarkup::class)
|
||||
object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(KeyboardMarkup::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: KeyboardMarkup) {
|
||||
when(obj) {
|
||||
is ForceReply -> ForceReply.serializer().serialize(encoder, obj)
|
||||
@ -12,4 +14,8 @@ object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
|
||||
is ReplyKeyboardRemove -> ReplyKeyboardRemove.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): KeyboardMarkup {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user