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