diff --git a/TelegramBotAPI/build.gradle b/TelegramBotAPI/build.gradle index 85296ef5fe..c475e31eed 100644 --- a/TelegramBotAPI/build.gradle +++ b/TelegramBotAPI/build.gradle @@ -39,6 +39,7 @@ kotlin { implementation kotlin('stdlib') api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version" api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-properties-common:$kotlin_serialisation_runtime_version" api "com.soywiz.korlibs.klock:klock:$klock_version" api "com.benasher44:uuid:$uuid_version" @@ -56,6 +57,7 @@ kotlin { jvmMain { dependencies { api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-properties:$kotlin_serialisation_runtime_version" api "io.ktor:ktor-client:$ktor_version" api "io.ktor:ktor-server:$ktor_version" @@ -73,6 +75,7 @@ kotlin { jsMain { dependencies { api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-properties-js:$kotlin_serialisation_runtime_version" api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version" api "io.ktor:ktor-client-js:$ktor_version" } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt index 33d33a6bcc..ae1f2a4407 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt @@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.types.Response import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import io.ktor.client.HttpClient import io.ktor.client.call.receive import io.ktor.client.features.* @@ -25,7 +26,7 @@ class KtorRequestsExecutor( callsFactories: List = emptyList(), excludeDefaultFactories: Boolean = false, private val requestsLimiter: RequestLimiter = EmptyLimiter, - private val jsonFormatter: Json = Json.nonstrict + private val jsonFormatter: Json = nonstrictJsonFormat ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { private val callsFactories: List = callsFactories.run { if (!excludeDefaultFactories) { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt index 4ec766ec53..4db320d4c0 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions import com.github.insanusmokrassar.TelegramBotAPI.types.Response -import kotlinx.io.IOException +import io.ktor.utils.io.errors.IOException fun newRequestException( response: Response, diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt index d5280dabae..33437adbfc 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class DeleteMessage( @@ -19,7 +19,7 @@ data class DeleteMessage( override fun method(): String = "deleteMessage" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index 4c5a4547c4..5f89bcc368 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -5,9 +5,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer -private val updatesListSerializer = ArrayListSerializer( +private val updatesListSerializer = ListSerializer( UpdateSerializerWithoutDeserialization ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt index 4a7cebba14..6744a78c37 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt @@ -22,8 +22,8 @@ fun String.toInputFile() = FileId(this) @Serializer(InputFile::class) internal object InputFileSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString()) - override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId) + override val descriptor: SerialDescriptor = PrimitiveDescriptor(FileId::class.toString(), PrimitiveKind.STRING) + override fun serialize(encoder: Encoder, value: InputFile) = encoder.encodeString(value.fileId) override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString()) } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt index 74465b9d26..5ddac8095a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class AnswerCallbackQuery( @@ -22,7 +22,7 @@ data class AnswerCallbackQuery( ) : SimpleRequest { override fun method(): String = "answerCallbackQuery" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt index 0fb9a4097a..039c038243 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt @@ -1,14 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.InlineQuery import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class AnswerInlineQuery( @@ -30,7 +29,7 @@ data class AnswerInlineQuery( ): SimpleRequest { override fun method(): String = "answerInlineQuery" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } @@ -52,6 +51,6 @@ fun InlineQuery.createAnswer( switchPmParameter ) -internal object InlineQueryAnswersResultsSerializer: KSerializer> by ArrayListSerializer( +internal object InlineQueryAnswersResultsSerializer: KSerializer> by ListSerializer( InlineQueryResultSerializer ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt index 8a9c41d455..5e61840797 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt @@ -1,12 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerShippingQuery import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer @Serializable data class AnswerShippingQueryOk( @@ -22,7 +21,7 @@ data class AnswerShippingQueryOk( get() = serializer() } -internal object ShippingOptionsSerializer : KSerializer> by ArrayListSerializer( +internal object ShippingOptionsSerializer : KSerializer> by ListSerializer( ShippingOption.serializer() ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerPreCheckoutQuery.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerPreCheckoutQuery.kt index 20388ba7e2..4fcca89ae9 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerPreCheckoutQuery.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerPreCheckoutQuery.kt @@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId import kotlinx.serialization.KSerializer -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer interface AnswerPreCheckoutQuery : SimpleRequest { override fun method(): String = "answerPreCheckoutQuery" override val resultDeserializer: KSerializer - get() = BooleanSerializer + get() = Boolean.serializer() val preCheckoutQueryId: PreCheckoutQueryId val isOk: Boolean diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerShippingQuery.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerShippingQuery.kt index cf9b8f3e5b..49dcba9c5e 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerShippingQuery.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/abstracts/AnswerShippingQuery.kt @@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer interface AnswerShippingQuery : SimpleRequest { override fun method(): String = "answerShippingQuery" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() val shippingQueryId: ShippingQueryIdentifier val isOk: Boolean diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt index a0532da8a9..67bcb3b17a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt @@ -1,13 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.StringSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class ExportChatInviteLink( @@ -16,7 +14,7 @@ data class ExportChatInviteLink( ): ChatRequest, SimpleRequest { override fun method(): String = "exportChatInviteLink" override val resultDeserializer: DeserializationStrategy - get() = StringSerializer + get() = String.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt index 956e2e4a43..ea0d1dc729 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class LeaveChat( @@ -16,7 +16,7 @@ data class LeaveChat( ): ChatRequest, SimpleRequest { override fun method(): String = "leaveChat" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt index 0e43498c1c..a2ae400d83 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt @@ -9,9 +9,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.Adm import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer -private val chatMembersListSerializer = ArrayListSerializer( +private val chatMembersListSerializer = ListSerializer( AdministratorChatMemberSerializerWithoutDeserialization ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt index 2ba659c347..85b24b0cc0 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.IntSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class GetChatMembersCount( @@ -16,7 +16,7 @@ data class GetChatMembersCount( ): ChatRequest, SimpleRequest { override fun method(): String = "getChatMembersCount" override val resultDeserializer: DeserializationStrategy - get() = IntSerializer + get() = Int.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt index 740a699cc7..6fb3ebafc9 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class KickChatMember( @@ -19,7 +19,7 @@ data class KickChatMember( ) : ChatMemberRequest, UntilDate { override fun method(): String = "kickChatMember" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt index 1e8a9eeb91..bee0174a14 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class PromoteChatMember( @@ -35,7 +35,7 @@ data class PromoteChatMember( ) : ChatMemberRequest, UntilDate { override fun method(): String = "promoteChatMember" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt index 2986af0c7c..d7cc099c8b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class RestrictChatMember( @@ -22,7 +22,7 @@ data class RestrictChatMember( ) : ChatMemberRequest, UntilDate { override fun method(): String = "restrictChatMember" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt index 91785b0299..c97035fb38 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer /** * Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle @@ -23,7 +23,7 @@ data class SetChatAdministratorCustomTitle( ) : ChatMemberRequest { override fun method(): String = "setChatAdministratorCustomTitle" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = RestrictChatMember.serializer() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt index 005efe98e6..c7f47f66f9 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class UnbanChatMember( @@ -16,7 +16,7 @@ data class UnbanChatMember( ) : ChatMemberRequest { override fun method(): String = "unbanChatMember" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt index c88c03cfc7..3be6760e48 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class DeleteChatPhoto( @@ -16,7 +16,7 @@ data class DeleteChatPhoto( ): ChatRequest, SimpleRequest { override fun method(): String = "deleteChatPhoto" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index a1d32f2209..41af62b0c3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -1,13 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class PinChatMessage ( @@ -20,7 +17,7 @@ data class PinChatMessage ( ): ChatRequest, SimpleRequest, MessageAction, DisableNotification { override fun method(): String = "pinChatMessage" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt index f62656f2cc..3dc2e89011 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class SetChatDescription ( @@ -23,7 +23,7 @@ data class SetChatDescription ( override fun method(): String = "setChatDescription" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt index 6909f1426f..96b5d3b5a5 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class SetChatPermissions ( @@ -18,7 +18,7 @@ data class SetChatPermissions ( ): ChatRequest, SimpleRequest { override fun method(): String = "setChatPermissions" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt index 7d4ef9b408..52a623ca5e 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt @@ -8,7 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.utils.toJson import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.JsonObject @Serializable @@ -19,7 +19,7 @@ data class SetChatPhoto ( ): ChatRequest, MultipartRequest { override fun method(): String = "setChatPhoto" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val mediaMap: Map = mapOf(photoField to photo) override val paramsJson: JsonObject = toJson(serializer()) } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt index ba86c5954b..b1fd4d2161 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class SetChatTitle ( @@ -23,7 +23,7 @@ data class SetChatTitle ( override fun method(): String = "setChatTitle" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt index 8fee87557c..911e80fec3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class UnpinChatMessage( @@ -16,7 +16,7 @@ data class UnpinChatMessage( ): ChatRequest, SimpleRequest { override fun method(): String = "unpinChatMessage" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt index bd27af1f3e..42e5fd8268 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class DeleteChatStickerSet( @@ -16,7 +16,7 @@ data class DeleteChatStickerSet( ): ChatRequest, SimpleRequest { override fun method(): String = "deleteChatStickerSet" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 4529f7c83e..144691c4b6 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class SetChatStickerSet( @@ -17,7 +17,7 @@ data class SetChatStickerSet( ): ChatRequest, SimpleRequest { override fun method(): String = "setChatStickerSet" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditInlineMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditInlineMessage.kt index c2cf5fed0a..ae90e47c59 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditInlineMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditInlineMessage.kt @@ -3,10 +3,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer interface EditInlineMessage : SimpleRequest { val inlineMessageId: InlineMessageIdentifier override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() } \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/GetGameHighScores.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/GetGameHighScores.kt index 0915454e86..a4017a85fa 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/GetGameHighScores.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/GetGameHighScores.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.games.GameHighScore import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.KSerializer -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer interface GetGameHighScores : SimpleRequest> { val userId: UserId @@ -15,4 +15,4 @@ interface GetGameHighScores : SimpleRequest> { get() = GameHighScoresSerializer } -internal object GameHighScoresSerializer : KSerializer> by ArrayListSerializer(GameHighScore.serializer()) +internal object GameHighScoresSerializer : KSerializer> by ListSerializer(GameHighScore.serializer()) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/SetGameScore.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/SetGameScore.kt index b0498392f1..285119fc0e 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/SetGameScore.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/abstracts/SetGameScore.kt @@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.serializer interface SetGameScore : SimpleRequest { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt index 65fc2f4d36..154db6fcb9 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.actions.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer /** * Send notification to user which will be shown for 5 seconds or while user have no messages from bot @@ -20,7 +20,7 @@ data class SendAction( ): SendChatMessageRequest { override fun method(): String = "sendChatAction" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt index 63bae97836..f2e2f1b3b5 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt @@ -12,7 +12,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaG import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.jsonArray val membersCountInMediaGroup: IntRange = 2 .. 10 @@ -55,8 +55,8 @@ fun SendMediaGroup( } } -private val messagesListSerializer: ArrayListSerializer - = ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) +private val messagesListSerializer: KSerializer> + = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) @Serializable data class SendMediaGroupData internal constructor( diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt index 46e52b243b..adbc82f59f 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import com.github.insanusmokrassar.TelegramBotAPI.types.stickerField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class DeleteStickerFromSet( @@ -15,7 +15,7 @@ data class DeleteStickerFromSet( ) : SimpleRequest { override fun method(): String = "deleteStickerFromSet" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt index fb71206675..a60bb1012b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import com.github.insanusmokrassar.TelegramBotAPI.types.positionField import com.github.insanusmokrassar.TelegramBotAPI.types.stickerField import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable data class SetStickerPositionInSet( @@ -24,7 +24,7 @@ data class SetStickerPositionInSet( override fun method(): String = "setStickerPositionInSet" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt index d46e316e71..7563fb0752 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt @@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.KSerializer -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer interface StickerSetAction : SimpleRequest { val userId: UserId @@ -13,5 +13,5 @@ interface StickerSetAction : SimpleRequest { val maskPosition: MaskPosition? override val resultDeserializer: KSerializer - get() = BooleanSerializer + get() = Boolean.serializer() } \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/DeleteWebhook.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/DeleteWebhook.kt index b061cfb830..27a1df4256 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/DeleteWebhook.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/DeleteWebhook.kt @@ -2,14 +2,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer @Serializable class DeleteWebhook : SimpleRequest { override fun method(): String = "deleteWebhook" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt index 305611f57a..a29d9f2b9a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt @@ -6,7 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.DataR import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.MultipartRequestImpl import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* -import kotlinx.serialization.internal.BooleanSerializer +import kotlinx.serialization.builtins.serializer fun SetWebhook( url: String, @@ -53,7 +53,7 @@ data class SetWebhook internal constructor( ) : DataRequest { override fun method(): String = "setWebhook" override val resultDeserializer: DeserializationStrategy - get() = BooleanSerializer + get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt index cc6d97f46e..a871bceaa3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt @@ -49,10 +49,10 @@ internal object ChatIdentifierSerializer : KSerializer { } } - override fun serialize(encoder: Encoder, obj: ChatIdentifier) { - when (obj) { - is ChatId -> encoder.encodeLong(obj.chatId) - is Username -> encoder.encodeString(obj.username) + override fun serialize(encoder: Encoder, value: ChatIdentifier) { + when (value) { + is ChatId -> encoder.encodeLong(value.chatId) + is Username -> encoder.encodeString(value.username) } } } \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt index 4137309d63..7a00b7b6ed 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt @@ -10,16 +10,16 @@ interface ChatMember { } internal object AdministratorChatMemberSerializerWithoutDeserialization : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("ChatMemberSerializerWithoutDeserialization") + override val descriptor: SerialDescriptor = ChatMemberDeserializationStrategy.descriptor override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberDeserializationStrategy.deserialize(decoder) as AdministratorChatMember - override fun serialize(encoder: Encoder, obj: AdministratorChatMember) = throw UnsupportedOperationException() + override fun serialize(encoder: Encoder, value: AdministratorChatMember) = throw UnsupportedOperationException() } internal object ChatMemberDeserializationStrategy : DeserializationStrategy { - override val descriptor: SerialDescriptor = StringDescriptor.withName("ChatMemberDeserializationStrategy") + override val descriptor: SerialDescriptor = RawChatMember.serializer().descriptor override fun deserialize(decoder: Decoder): ChatMember = RawChatMember.serializer().deserialize(decoder).asChatMember - override fun patch(decoder: Decoder, old: ChatMember): ChatMember = throw UpdateNotSupportedException(descriptor.name) + override fun patch(decoder: Decoder, old: ChatMember): ChatMember = throw UpdateNotSupportedException("ChatMember") } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt index e114e76a84..a030020254 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt @@ -7,29 +7,29 @@ import kotlinx.serialization.internal.StringDescriptor @Serializer(InlineQueryResult::class) internal object InlineQueryResultSerializer : KSerializer { - 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) - is InlineQueryResultAudioCachedImpl -> InlineQueryResultAudioCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultAudioImpl -> InlineQueryResultAudioImpl.serializer().serialize(encoder, obj) - is InlineQueryResultContact -> InlineQueryResultContact.serializer().serialize(encoder, obj) - is InlineQueryResultDocumentCachedImpl -> InlineQueryResultDocumentCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultDocumentImpl -> InlineQueryResultDocumentImpl.serializer().serialize(encoder, obj) - is InlineQueryResultGame -> InlineQueryResultGame.serializer().serialize(encoder, obj) - is InlineQueryResultGifCachedImpl -> InlineQueryResultGifCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultGifImpl -> InlineQueryResultGifImpl.serializer().serialize(encoder, obj) - is InlineQueryResultLocation -> InlineQueryResultLocation.serializer().serialize(encoder, obj) - is InlineQueryResultMpeg4GifCachedImpl -> InlineQueryResultMpeg4GifCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultMpeg4GifImpl -> InlineQueryResultMpeg4GifImpl.serializer().serialize(encoder, obj) - is InlineQueryResultPhotoCachedImpl -> InlineQueryResultPhotoCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultPhotoImpl -> InlineQueryResultPhotoImpl.serializer().serialize(encoder, obj) - is InlineQueryResultStickerCached -> InlineQueryResultStickerCached.serializer().serialize(encoder, obj) - is InlineQueryResultVenue -> InlineQueryResultVenue.serializer().serialize(encoder, obj) - is InlineQueryResultVideoCachedImpl -> InlineQueryResultVideoCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultVideoImpl -> InlineQueryResultVideoImpl.serializer().serialize(encoder, obj) - is InlineQueryResultVoiceCachedImpl -> InlineQueryResultVoiceCachedImpl.serializer().serialize(encoder, obj) - is InlineQueryResultVoiceImpl -> InlineQueryResultVoiceImpl.serializer().serialize(encoder, obj) + override val descriptor: SerialDescriptor = SerialDescriptor(InlineQueryResult::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: InlineQueryResult) { + when(value) { + is InlineQueryResultArticle -> InlineQueryResultArticle.serializer().serialize(encoder, value) + is InlineQueryResultAudioCachedImpl -> InlineQueryResultAudioCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultAudioImpl -> InlineQueryResultAudioImpl.serializer().serialize(encoder, value) + is InlineQueryResultContact -> InlineQueryResultContact.serializer().serialize(encoder, value) + is InlineQueryResultDocumentCachedImpl -> InlineQueryResultDocumentCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultDocumentImpl -> InlineQueryResultDocumentImpl.serializer().serialize(encoder, value) + is InlineQueryResultGame -> InlineQueryResultGame.serializer().serialize(encoder, value) + is InlineQueryResultGifCachedImpl -> InlineQueryResultGifCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultGifImpl -> InlineQueryResultGifImpl.serializer().serialize(encoder, value) + is InlineQueryResultLocation -> InlineQueryResultLocation.serializer().serialize(encoder, value) + is InlineQueryResultMpeg4GifCachedImpl -> InlineQueryResultMpeg4GifCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultMpeg4GifImpl -> InlineQueryResultMpeg4GifImpl.serializer().serialize(encoder, value) + is InlineQueryResultPhotoCachedImpl -> InlineQueryResultPhotoCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultPhotoImpl -> InlineQueryResultPhotoImpl.serializer().serialize(encoder, value) + is InlineQueryResultStickerCached -> InlineQueryResultStickerCached.serializer().serialize(encoder, value) + is InlineQueryResultVenue -> InlineQueryResultVenue.serializer().serialize(encoder, value) + is InlineQueryResultVideoCachedImpl -> InlineQueryResultVideoCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultVideoImpl -> InlineQueryResultVideoImpl.serializer().serialize(encoder, value) + is InlineQueryResultVoiceCachedImpl -> InlineQueryResultVoiceCachedImpl.serializer().serialize(encoder, value) + is InlineQueryResultVoiceImpl -> InlineQueryResultVoiceImpl.serializer().serialize(encoder, value) } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InputMessageContentSerializer.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InputMessageContentSerializer.kt index 4eca591bbe..d1d6adfc67 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InputMessageContentSerializer.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InputMessageContentSerializer.kt @@ -7,13 +7,13 @@ import kotlinx.serialization.internal.StringDescriptor @Serializer(InputMessageContent::class) internal object InputMessageContentSerializer : KSerializer { - 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) - is InputLocationMessageContent -> InputLocationMessageContent.serializer().serialize(encoder, obj) - is InputTextMessageContent -> InputTextMessageContent.serializer().serialize(encoder, obj) - is InputVenueMessageContent -> InputVenueMessageContent.serializer().serialize(encoder, obj) + override val descriptor: SerialDescriptor = SerialDescriptor(InputMessageContent::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: InputMessageContent) { + when (value) { + is InputContactMessageContent -> InputContactMessageContent.serializer().serialize(encoder, value) + is InputLocationMessageContent -> InputLocationMessageContent.serializer().serialize(encoder, value) + is InputTextMessageContent -> InputTextMessageContent.serializer().serialize(encoder, value) + is InputVenueMessageContent -> InputVenueMessageContent.serializer().serialize(encoder, value) else -> throw IllegalArgumentException("Unknown for serializing InputContactMessageContent") } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt index 2e5ea13d13..e98e8b38f7 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt @@ -25,7 +25,7 @@ data class InputMediaPhoto( } @Transient - override val arguments: Map = Mapper.mapNullable(serializer(), this) + override val arguments: Map = Properties.storeNullable(serializer(), this) } fun PhotoSize.toInputMediaPhoto( diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaSerializer.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaSerializer.kt index 72b2f98050..078fc8448a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaSerializer.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaSerializer.kt @@ -5,15 +5,15 @@ import kotlinx.serialization.internal.StringDescriptor @Serializer(InputMedia::class) internal object InputMediaSerializer : KSerializer { - 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) - 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 val descriptor: SerialDescriptor = SerialDescriptor(InputMedia::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: InputMedia) { + when (value) { + is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, value) + is InputMediaAudio -> InputMediaAudio.serializer().serialize(encoder, value) + is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, value) + is InputMediaAnimation -> InputMediaAnimation.serializer().serialize(encoder, value) + is InputMediaDocument -> InputMediaDocument.serializer().serialize(encoder, value) + else -> throw IllegalArgumentException("Can't perform and serialize $value") } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt index faf5a15f3c..1c32f30adb 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt @@ -28,5 +28,5 @@ data class InputMediaVideo( } @Transient - override val arguments: Map = Mapper.mapNullable(serializer(), this) + override val arguments: Map = Properties.storeNullable(serializer(), this) } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt index 235b67e871..5f097f33fd 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt @@ -5,11 +5,11 @@ import kotlinx.serialization.internal.StringDescriptor @Serializer(MediaGroupMemberInputMedia::class) internal object MediaGroupMemberInputMediaSerializer : KSerializer { - 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 val descriptor: SerialDescriptor = SerialDescriptor(MediaGroupMemberInputMedia::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: MediaGroupMemberInputMedia) { + when (value) { + is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, value) + is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, value) } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ParseMode/ParseMode.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ParseMode/ParseMode.kt index e3558593d7..9e53d9b5d7 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ParseMode/ParseMode.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ParseMode/ParseMode.kt @@ -43,7 +43,7 @@ internal object ParseModeSerializerObject : KSerializer { } } - override fun serialize(encoder: Encoder, obj: ParseMode) { - encoder.encodeString(obj.parseModeName) + override fun serialize(encoder: Encoder, value: ParseMode) { + encoder.encodeString(value.parseModeName) } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/TelegramDate.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/TelegramDate.kt index 62e19cbbf0..f4ac135f99 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/TelegramDate.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/TelegramDate.kt @@ -24,9 +24,9 @@ fun DateTime.toTelegramDate(): TelegramDate = TelegramDate(this) @Serializer(TelegramDate::class) internal object TelegramDateSerializer : KSerializer { - override fun serialize(encoder: Encoder, obj: TelegramDate) { + override fun serialize(encoder: Encoder, value: TelegramDate) { encoder.encodeLong( - obj.date + value.date ) } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt index 8362b2cd42..a4cefd2b2b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObjectSerializer @@ -67,7 +68,7 @@ internal object UserSerializer : KSerializer { val asJson = JsonObjectSerializer.deserialize(decoder) return when { - asJson.getPrimitiveOrNull(isBotField) ?.booleanOrNull != true -> Json.nonstrict.fromJson( + asJson.getPrimitiveOrNull(isBotField) ?.booleanOrNull != true -> nonstrictJsonFormat.fromJson( CommonUser.serializer(), asJson ) @@ -76,12 +77,12 @@ internal object UserSerializer : KSerializer { ?: asJson.get(canReadAllGroupMessagesField) ?: asJson.get(supportInlineQueriesField)) != null ) { - Json.nonstrict.fromJson( + nonstrictJsonFormat.fromJson( ExtendedBot.serializer(), asJson ) } else { - Json.nonstrict.fromJson( + nonstrictJsonFormat.fromJson( CommonBot.serializer(), asJson ) @@ -90,11 +91,11 @@ internal object UserSerializer : KSerializer { } } - override fun serialize(encoder: Encoder, obj: User) { - when (obj) { - is CommonUser -> CommonUser.serializer().serialize(encoder, obj) - is CommonBot -> CommonBot.serializer().serialize(encoder, obj) - is ExtendedBot -> ExtendedBot.serializer().serialize(encoder, obj) + override fun serialize(encoder: Encoder, value: User) { + when (value) { + is CommonUser -> CommonUser.serializer().serialize(encoder, value) + is CommonBot -> CommonBot.serializer().serialize(encoder, value) + is ExtendedBot -> ExtendedBot.serializer().serialize(encoder, value) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UserProfilePhotos.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UserProfilePhotos.kt index 133610427b..21cdc9d9d5 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UserProfilePhotos.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UserProfilePhotos.kt @@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types import com.github.insanusmokrassar.TelegramBotAPI.types.files.Photo import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSerializer import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer @Serializable data class UserProfilePhotos ( @@ -13,6 +13,6 @@ data class UserProfilePhotos ( val photos: List ) -internal object UserProfilePhotosPhotosSerializer : KSerializer> by ArrayListSerializer( +internal object UserProfilePhotosPhotosSerializer : KSerializer> by ListSerializer( PhotoSerializer ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt index 5f0915a211..f8bd33f045 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt @@ -9,8 +9,8 @@ sealed class BotAction { @Serializer(BotAction::class) internal object BotActionSerializer: KSerializer { - override fun serialize(encoder: Encoder, obj: BotAction) { - encoder.encodeString(obj.actionName) + override fun serialize(encoder: Encoder, value: BotAction) { + encoder.encodeString(value.actionName) } override fun deserialize(decoder: Decoder): BotAction { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt index 317cc57901..9d5a7c94c0 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt @@ -1,12 +1,16 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* import kotlinx.serialization.internal.StringDescriptor import kotlinx.serialization.json.* internal object InlineKeyboardButtonSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton") + override val descriptor: SerialDescriptor = SerialDescriptor( + "com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton", + PolymorphicKind.SEALED + ) private fun resolveSerializer(json: JsonObject): KSerializer { return when { @@ -23,17 +27,17 @@ internal object InlineKeyboardButtonSerializer : KSerializer CallbackDataInlineKeyboardButton.serializer().serialize(encoder, obj) - is LoginURLInlineKeyboardButton -> LoginURLInlineKeyboardButton.serializer().serialize(encoder, obj) - is PayInlineKeyboardButton -> PayInlineKeyboardButton.serializer().serialize(encoder, obj) - is SwitchInlineQueryInlineKeyboardButton -> SwitchInlineQueryInlineKeyboardButton.serializer().serialize(encoder, obj) - is SwitchInlineQueryCurrentChatInlineKeyboardButton -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer().serialize(encoder, obj) - is URLInlineKeyboardButton -> URLInlineKeyboardButton.serializer().serialize(encoder, obj) + override fun serialize(encoder: Encoder, value: InlineKeyboardButton) { + when (value) { + is CallbackDataInlineKeyboardButton -> CallbackDataInlineKeyboardButton.serializer().serialize(encoder, value) + is LoginURLInlineKeyboardButton -> LoginURLInlineKeyboardButton.serializer().serialize(encoder, value) + is PayInlineKeyboardButton -> PayInlineKeyboardButton.serializer().serialize(encoder, value) + is SwitchInlineQueryInlineKeyboardButton -> SwitchInlineQueryInlineKeyboardButton.serializer().serialize(encoder, value) + is SwitchInlineQueryCurrentChatInlineKeyboardButton -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer().serialize(encoder, value) + is URLInlineKeyboardButton -> URLInlineKeyboardButton.serializer().serialize(encoder, value) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButton.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButton.kt index de8eee0c55..f913c0d07a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButton.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButton.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* import kotlinx.serialization.json.* @@ -58,7 +59,7 @@ internal object KeyboardButtonSerializer : KSerializer { ) asJson is JsonObject && asJson.getObjectOrNull(requestPollField) != null -> RequestPollKeyboardButton( asJson.getPrimitive(textField).content, - Json.nonstrict.fromJson( + nonstrictJsonFormat.fromJson( KeyboardButtonPollType.serializer(), asJson.getObject(requestPollField) ) @@ -74,13 +75,13 @@ internal object KeyboardButtonSerializer : KSerializer { } } - override fun serialize(encoder: Encoder, obj: KeyboardButton) { - when (obj) { - is RequestContactKeyboardButton -> RequestContactKeyboardButton.serializer().serialize(encoder, obj) - is RequestLocationKeyboardButton -> RequestLocationKeyboardButton.serializer().serialize(encoder, obj) - is RequestPollKeyboardButton -> RequestPollKeyboardButton.serializer().serialize(encoder, obj) - is SimpleKeyboardButton -> encoder.encodeString(obj.text) - is UnknownKeyboardButton -> JsonElementSerializer.serialize(encoder, Json.nonstrict.parseJson(obj.raw)) + override fun serialize(encoder: Encoder, value: KeyboardButton) { + when (value) { + is RequestContactKeyboardButton -> RequestContactKeyboardButton.serializer().serialize(encoder, value) + is RequestLocationKeyboardButton -> RequestLocationKeyboardButton.serializer().serialize(encoder, value) + is RequestPollKeyboardButton -> RequestPollKeyboardButton.serializer().serialize(encoder, value) + is SimpleKeyboardButton -> encoder.encodeString(value.text) + is UnknownKeyboardButton -> JsonElementSerializer.serialize(encoder, nonstrictJsonFormat.parseJson(value.raw)) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButtonPollType.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButtonPollType.kt index b4140699f3..aef28823a3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButtonPollType.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/KeyboardButtonPollType.kt @@ -42,12 +42,12 @@ internal object KeyboardButtonPollTypeSerializer : KSerializer { - 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) - is InlineKeyboardMarkup -> InlineKeyboardMarkup.serializer().serialize(encoder, obj) - is ReplyKeyboardMarkup -> ReplyKeyboardMarkup.serializer().serialize(encoder, obj) - is ReplyKeyboardRemove -> ReplyKeyboardRemove.serializer().serialize(encoder, obj) + override val descriptor: SerialDescriptor = SerialDescriptor( + KeyboardMarkup::class.toString(), + PolymorphicKind.OPEN + ) + override fun serialize(encoder: Encoder, value: KeyboardMarkup) { + when(value) { + is ForceReply -> ForceReply.serializer().serialize(encoder, value) + is InlineKeyboardMarkup -> InlineKeyboardMarkup.serializer().serialize(encoder, value) + is ReplyKeyboardMarkup -> ReplyKeyboardMarkup.serializer().serialize(encoder, value) + is ReplyKeyboardRemove -> ReplyKeyboardRemove.serializer().serialize(encoder, value) } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt index abb66ad729..927a59966a 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt @@ -5,16 +5,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UnknownChatType import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* -import kotlinx.serialization.internal.LongSerializer -import kotlinx.serialization.internal.StringDescriptor -import kotlinx.serialization.json.Json +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.JsonObjectSerializer -private val formatter = Json.nonstrict +private val formatter = nonstrictJsonFormat internal object PreviewChatSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + override val descriptor: SerialDescriptor = SerialDescriptor("PreviewChatSerializer", PolymorphicKind.OPEN) override fun deserialize(decoder: Decoder): Chat { val decodedJson = JsonObjectSerializer.deserialize(decoder) @@ -27,25 +26,25 @@ internal object PreviewChatSerializer : KSerializer { "supergroup" -> formatter.fromJson(SupergroupChatImpl.serializer(), decodedJson) "channel" -> formatter.fromJson(ChannelChatImpl.serializer(), decodedJson) else -> UnknownChatType( - formatter.fromJson(LongSerializer, decodedJson.getPrimitive(chatIdField)).toChatId(), + formatter.fromJson(Long.serializer(), decodedJson.getPrimitive(chatIdField)).toChatId(), decodedJson.toString() ) } } - override fun serialize(encoder: Encoder, obj: Chat) { - when (obj) { - is ExtendedChat -> ExtendedChatSerializer.serialize(encoder, obj) - is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, obj) - is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, obj) - is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, obj) - is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, obj) + override fun serialize(encoder: Encoder, value: Chat) { + when (value) { + is ExtendedChat -> ExtendedChatSerializer.serialize(encoder, value) + is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, value) + is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, value) + is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, value) + is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, value) } } } internal object ExtendedChatSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + override val descriptor: SerialDescriptor = SerialDescriptor("PreviewChatSerializer", PolymorphicKind.OPEN) override fun deserialize(decoder: Decoder): ExtendedChat { val decodedJson = JsonObjectSerializer.deserialize(decoder) @@ -61,12 +60,12 @@ internal object ExtendedChatSerializer : KSerializer { } } - override fun serialize(encoder: Encoder, obj: ExtendedChat) { - when (obj) { - is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, obj) - is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, obj) - is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, obj) - is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, obj) + override fun serialize(encoder: Encoder, value: ExtendedChat) { + when (value) { + is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, value) + is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, value) + is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, value) + is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, value) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt index 93f9ae1b39..360070e62c 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.* import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer typealias Photo = List @@ -13,7 +13,7 @@ fun Photo.biggest(): PhotoSize? = maxBy { it.resolution } -internal object PhotoSerializer : KSerializer by ArrayListSerializer( +internal object PhotoSerializer : KSerializer by ListSerializer( PhotoSize.serializer() ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt index 7a809c8b46..63f7dd4ce6 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt @@ -21,9 +21,9 @@ data class UnknownMessageType( ) : Message internal class TelegramBotAPIMessageDeserializationStrategyClass : DeserializationStrategy { - override val descriptor: SerialDescriptor = StringDescriptor.withName("TelegramBotAPIMessageSerializer") + override val descriptor: SerialDescriptor = SerialDescriptor("TelegramBotAPIMessageSerializer", PolymorphicKind.OPEN) - override fun patch(decoder: Decoder, old: T): T = throw UpdateNotSupportedException(descriptor.name) + override fun patch(decoder: Decoder, old: T): T = throw UpdateNotSupportedException("TelegramBotAPIMessageSerializer") override fun deserialize(decoder: Decoder): T { return RawMessage.serializer().deserialize(decoder).asMessage as T } @@ -40,7 +40,7 @@ internal class TelegramBotAPIMessageDeserializeOnlySerializerClass return deserializer.deserialize(decoder) } - override fun serialize(encoder: Encoder, obj: T) { + override fun serialize(encoder: Encoder, value: T) { throw UnsupportedOperationException("Currently, Message objects can't be serialized y this serializer") } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/payments/ShippingOption.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/payments/ShippingOption.kt index 95ab6ca48a..6fe86673e2 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/payments/ShippingOption.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/payments/ShippingOption.kt @@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.payments import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.Priced import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer @Serializable data class ShippingOption( @@ -16,6 +16,6 @@ data class ShippingOption( override val prices: List ) : Priced -internal object LabeledPricesSerializer : KSerializer> by ArrayListSerializer( +internal object LabeledPricesSerializer : KSerializer> by ListSerializer( LabeledPrice.serializer() ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt index 5334927df4..2c9990e5b5 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt @@ -1,8 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.polls import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* -import kotlinx.serialization.internal.ArrayListSerializer +import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.* @Serializable(PollSerializer::class) @@ -73,23 +74,23 @@ data class QuizPoll( @Serializer(Poll::class) internal object PollSerializer : KSerializer { - private val pollOptionsSerializer = ArrayListSerializer(PollOption.serializer()) + private val pollOptionsSerializer = ListSerializer(PollOption.serializer()) override fun deserialize(decoder: Decoder): Poll { val asJson = JsonObjectSerializer.deserialize(decoder) return when (asJson.getPrimitive(typeField).content) { - regularPollType -> Json.nonstrict.fromJson( + regularPollType -> nonstrictJsonFormat.fromJson( RegularPoll.serializer(), asJson ) - quizPollType -> Json.nonstrict.fromJson( + quizPollType -> nonstrictJsonFormat.fromJson( QuizPoll.serializer(), asJson ) else -> UnknownPollType( asJson.getPrimitive(idField).content, asJson.getPrimitive(questionField).content, - Json.nonstrict.fromJson( + nonstrictJsonFormat.fromJson( pollOptionsSerializer, asJson.getArray(optionsField) ), @@ -101,17 +102,17 @@ internal object PollSerializer : KSerializer { } } - override fun serialize(encoder: Encoder, obj: Poll) { - val asJson = when (obj) { - is RegularPoll -> Json.nonstrict.toJson(RegularPoll.serializer(), obj) - is QuizPoll -> Json.nonstrict.toJson(QuizPoll.serializer(), obj) - is UnknownPollType -> throw IllegalArgumentException("Currently unable to correctly serialize object of poll $obj") + override fun serialize(encoder: Encoder, value: Poll) { + val asJson = when (value) { + is RegularPoll -> nonstrictJsonFormat.toJson(RegularPoll.serializer(), value) + is QuizPoll -> nonstrictJsonFormat.toJson(QuizPoll.serializer(), value) + is UnknownPollType -> throw IllegalArgumentException("Currently unable to correctly serialize object of poll $value") } val resultJson = JsonObject( - asJson.jsonObject + (typeField to when (obj) { + asJson.jsonObject + (typeField to when (value) { is RegularPoll -> JsonPrimitive(regularPollType) is QuizPoll -> JsonPrimitive(quizPollType) - is UnknownPollType -> throw IllegalArgumentException("Currently unable to correctly serialize object of poll $obj") + is UnknownPollType -> throw IllegalArgumentException("Currently unable to correctly serialize object of poll $value") }) ) JsonObjectSerializer.serialize(encoder, resultJson) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt index 247a7567aa..feebf09325 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt @@ -20,17 +20,17 @@ data class SimplePollOption ( ) : PollOption() internal object PollOptionSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName(PollOption::class.simpleName ?: "PollOption") + override val descriptor: SerialDescriptor = SimplePollOption.serializer().descriptor override fun deserialize(decoder: Decoder): PollOption = SimplePollOption.serializer().deserialize( decoder ) - override fun serialize(encoder: Encoder, obj: PollOption) { - when (obj) { + override fun serialize(encoder: Encoder, value: PollOption) { + when (value) { is SimplePollOption -> SimplePollOption.serializer().serialize( encoder, - obj + value ) } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt index 6d317c4071..536fd33827 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt @@ -2,9 +2,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate +import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import kotlinx.serialization.* -import kotlinx.serialization.internal.StringDescriptor -import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElementSerializer interface Update { @@ -18,21 +17,21 @@ data class UnknownUpdateType( ) : Update internal object UpdateSerializerWithoutDeserialization : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateSerializerWithoutDeserialization") + override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder) - override fun serialize(encoder: Encoder, obj: Update) = throw UnsupportedOperationException() + override fun serialize(encoder: Encoder, value: Update) = throw UnsupportedOperationException() } internal object UpdateDeserializationStrategy : DeserializationStrategy { - override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateDeserializationStrategy") + override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor - override fun patch(decoder: Decoder, old: Update): Update = throw UpdateNotSupportedException(descriptor.name) + override fun patch(decoder: Decoder, old: Update): Update = throw UpdateNotSupportedException("Update") override fun deserialize(decoder: Decoder): Update { val asJson = JsonElementSerializer.deserialize(decoder) - return Json.nonstrict.fromJson( + return nonstrictJsonFormat.fromJson( RawUpdate.serializer(), asJson ).asUpdate( diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/JSON.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/JSON.kt index 35e674808a..f579d13706 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/JSON.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/JSON.kt @@ -3,9 +3,16 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.json.* +val nonstrictJsonFormat = Json { + isLenient = true + ignoreUnknownKeys = true + serializeSpecialFloatingPointValues = true + useArrayPolymorphism = true +} + inline fun T.toJsonWithoutNulls(serializer: SerializationStrategy): JsonObject = toJson(serializer).withoutNulls() -inline fun T.toJson(serializer: SerializationStrategy): JsonObject = Json.nonstrict.toJson( +inline fun T.toJson(serializer: SerializationStrategy): JsonObject = nonstrictJsonFormat.toJson( serializer, this ).jsonObject