mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 09:07:12 +00:00
new libraries versions adaptation
This commit is contained in:
parent
574ffbc44d
commit
6b3f836096
@ -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"
|
||||
}
|
||||
|
@ -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<KtorCallFactory> = 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<KtorCallFactory> = callsFactories.run {
|
||||
if (!excludeDefaultFactories) {
|
||||
|
@ -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,
|
||||
|
@ -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<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -22,8 +22,8 @@ fun String.toInputFile() = FileId(this)
|
||||
|
||||
@Serializer(InputFile::class)
|
||||
internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
|
||||
override 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())
|
||||
}
|
||||
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "answerCallbackQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "answerInlineQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@ -52,6 +51,6 @@ fun InlineQuery.createAnswer(
|
||||
switchPmParameter
|
||||
)
|
||||
|
||||
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
|
||||
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ListSerializer(
|
||||
InlineQueryResultSerializer
|
||||
)
|
||||
|
@ -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<List<ShippingOption>> by ArrayListSerializer(
|
||||
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ListSerializer(
|
||||
ShippingOption.serializer()
|
||||
)
|
||||
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "answerPreCheckoutQuery"
|
||||
override val resultDeserializer: KSerializer<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
|
||||
val preCheckoutQueryId: PreCheckoutQueryId
|
||||
val isOk: Boolean
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "answerShippingQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
|
||||
val shippingQueryId: ShippingQueryIdentifier
|
||||
val isOk: Boolean
|
||||
|
@ -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<String> {
|
||||
override fun method(): String = "exportChatInviteLink"
|
||||
override val resultDeserializer: DeserializationStrategy<String>
|
||||
get() = StringSerializer
|
||||
get() = String.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "leaveChat"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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<Int> {
|
||||
override fun method(): String = "getChatMembersCount"
|
||||
override val resultDeserializer: DeserializationStrategy<Int>
|
||||
get() = IntSerializer
|
||||
get() = Int.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>, UntilDate {
|
||||
override fun method(): String = "kickChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>, UntilDate {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "setChatAdministratorCustomTitle"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = RestrictChatMember.serializer()
|
||||
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "unbanChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "deleteChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>, MessageAction, DisableNotification {
|
||||
override fun method(): String = "pinChatMessage"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "setChatPermissions"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
|
@ -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<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "unpinChatMessage"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "deleteChatStickerSet"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "setChatStickerSet"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
}
|
@ -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<List<GameHighScore>> {
|
||||
val userId: UserId
|
||||
@ -15,4 +15,4 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
|
||||
get() = GameHighScoresSerializer
|
||||
}
|
||||
|
||||
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
|
||||
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ListSerializer(GameHighScore.serializer())
|
||||
|
@ -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<Boolean> {
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "sendChatAction"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<MediaGroupMessage>
|
||||
= ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
|
||||
private val messagesListSerializer: KSerializer<List<MediaGroupMessage>>
|
||||
= ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
|
||||
|
||||
@Serializable
|
||||
data class SendMediaGroupData internal constructor(
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "deleteStickerFromSet"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
val userId: UserId
|
||||
@ -13,5 +13,5 @@ interface StickerSetAction : SimpleRequest<Boolean> {
|
||||
val maskPosition: MaskPosition?
|
||||
|
||||
override val resultDeserializer: KSerializer<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
}
|
@ -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<Boolean> {
|
||||
override fun method(): String = "deleteWebhook"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -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<Boolean> {
|
||||
override fun method(): String = "setWebhook"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
|
@ -49,10 +49,10 @@ internal object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
@ -10,16 +10,16 @@ interface ChatMember {
|
||||
}
|
||||
|
||||
internal object AdministratorChatMemberSerializerWithoutDeserialization : KSerializer<AdministratorChatMember> {
|
||||
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<ChatMember> {
|
||||
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")
|
||||
}
|
||||
|
@ -7,29 +7,29 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(InlineQueryResult::class)
|
||||
internal object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InlineQueryResult::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InlineQueryResult) {
|
||||
when(obj) {
|
||||
is InlineQueryResultArticle -> InlineQueryResultArticle.serializer().serialize(encoder, obj)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,13 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(InputMessageContent::class)
|
||||
internal object InputMessageContentSerializer : KSerializer<InputMessageContent> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMessageContent::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputMessageContent) {
|
||||
when (obj) {
|
||||
is InputContactMessageContent -> InputContactMessageContent.serializer().serialize(encoder, obj)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ data class InputMediaPhoto(
|
||||
}
|
||||
|
||||
@Transient
|
||||
override val arguments: Map<String, Any?> = Mapper.mapNullable(serializer(), this)
|
||||
override val arguments: Map<String, Any?> = Properties.storeNullable(serializer(), this)
|
||||
}
|
||||
|
||||
fun PhotoSize.toInputMediaPhoto(
|
||||
|
@ -5,15 +5,15 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(InputMedia::class)
|
||||
internal object InputMediaSerializer : KSerializer<InputMedia> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMedia::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputMedia) {
|
||||
when (obj) {
|
||||
is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, obj)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,5 +28,5 @@ data class InputMediaVideo(
|
||||
}
|
||||
|
||||
@Transient
|
||||
override val arguments: Map<String, Any?> = Mapper.mapNullable(serializer(), this)
|
||||
override val arguments: Map<String, Any?> = Properties.storeNullable(serializer(), this)
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(MediaGroupMemberInputMedia::class)
|
||||
internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(MediaGroupMemberInputMedia::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: MediaGroupMemberInputMedia) {
|
||||
when (obj) {
|
||||
is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, obj)
|
||||
is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, obj)
|
||||
override 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ internal object ParseModeSerializerObject : KSerializer<ParseMode> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: ParseMode) {
|
||||
encoder.encodeString(obj.parseModeName)
|
||||
override fun serialize(encoder: Encoder, value: ParseMode) {
|
||||
encoder.encodeString(value.parseModeName)
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ fun DateTime.toTelegramDate(): TelegramDate = TelegramDate(this)
|
||||
|
||||
@Serializer(TelegramDate::class)
|
||||
internal object TelegramDateSerializer : KSerializer<TelegramDate> {
|
||||
override fun serialize(encoder: Encoder, obj: TelegramDate) {
|
||||
override fun serialize(encoder: Encoder, value: TelegramDate) {
|
||||
encoder.encodeLong(
|
||||
obj.date
|
||||
value.date
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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<User> {
|
||||
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<User> {
|
||||
?: 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<User> {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Photo>
|
||||
)
|
||||
|
||||
internal object UserProfilePhotosPhotosSerializer : KSerializer<List<Photo>> by ArrayListSerializer(
|
||||
internal object UserProfilePhotosPhotosSerializer : KSerializer<List<Photo>> by ListSerializer(
|
||||
PhotoSerializer
|
||||
)
|
||||
|
@ -9,8 +9,8 @@ sealed class BotAction {
|
||||
|
||||
@Serializer(BotAction::class)
|
||||
internal object BotActionSerializer: KSerializer<BotAction> {
|
||||
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 {
|
||||
|
@ -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<InlineKeyboardButton> {
|
||||
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<out InlineKeyboardButton> {
|
||||
return when {
|
||||
@ -23,17 +27,17 @@ internal object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButto
|
||||
override fun deserialize(decoder: Decoder): InlineKeyboardButton {
|
||||
val json = JsonElementSerializer.deserialize(decoder)
|
||||
|
||||
return Json.nonstrict.fromJson(resolveSerializer(json.jsonObject), json)
|
||||
return nonstrictJsonFormat.fromJson(resolveSerializer(json.jsonObject), json)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: InlineKeyboardButton) {
|
||||
when (obj) {
|
||||
is CallbackDataInlineKeyboardButton -> 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<KeyboardButton> {
|
||||
)
|
||||
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<KeyboardButton> {
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ internal object KeyboardButtonPollTypeSerializer : KSerializer<KeyboardButtonPol
|
||||
/**
|
||||
* Crutch due to the fact that direct serialization of objects currently does not work perfectly
|
||||
*/
|
||||
override fun serialize(encoder: Encoder, obj: KeyboardButtonPollType) {
|
||||
override fun serialize(encoder: Encoder, value: KeyboardButtonPollType) {
|
||||
JsonObjectSerializer.serialize(
|
||||
encoder,
|
||||
JsonObject(
|
||||
mapOf(
|
||||
typeField to JsonPrimitive(obj.type)
|
||||
typeField to JsonPrimitive(value.type)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -5,13 +5,16 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializer(KeyboardMarkup::class)
|
||||
internal object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(KeyboardMarkup::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: KeyboardMarkup) {
|
||||
when(obj) {
|
||||
is ForceReply -> ForceReply.serializer().serialize(encoder, obj)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Chat> {
|
||||
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<Chat> {
|
||||
"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<ExtendedChat> {
|
||||
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<ExtendedChat> {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<PhotoSize>
|
||||
|
||||
@ -13,7 +13,7 @@ fun Photo.biggest(): PhotoSize? = maxBy {
|
||||
it.resolution
|
||||
}
|
||||
|
||||
internal object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
|
||||
internal object PhotoSerializer : KSerializer<Photo> by ListSerializer(
|
||||
PhotoSize.serializer()
|
||||
)
|
||||
|
||||
|
@ -21,9 +21,9 @@ data class UnknownMessageType(
|
||||
) : Message
|
||||
|
||||
internal class TelegramBotAPIMessageDeserializationStrategyClass<T> : DeserializationStrategy<T> {
|
||||
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<T : Message>
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -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<LabeledPrice>
|
||||
) : Priced
|
||||
|
||||
internal object LabeledPricesSerializer : KSerializer<List<LabeledPrice>> by ArrayListSerializer(
|
||||
internal object LabeledPricesSerializer : KSerializer<List<LabeledPrice>> by ListSerializer(
|
||||
LabeledPrice.serializer()
|
||||
)
|
||||
|
@ -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<Poll> {
|
||||
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<Poll> {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -20,17 +20,17 @@ data class SimplePollOption (
|
||||
) : PollOption()
|
||||
|
||||
internal object PollOptionSerializer : KSerializer<PollOption> {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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<Update> {
|
||||
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<Update> {
|
||||
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(
|
||||
|
@ -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: Any> T.toJsonWithoutNulls(serializer: SerializationStrategy<T>): JsonObject = toJson(serializer).withoutNulls()
|
||||
|
||||
inline fun <T: Any> T.toJson(serializer: SerializationStrategy<T>): JsonObject = Json.nonstrict.toJson(
|
||||
inline fun <T: Any> T.toJson(serializer: SerializationStrategy<T>): JsonObject = nonstrictJsonFormat.toJson(
|
||||
serializer,
|
||||
this
|
||||
).jsonObject
|
||||
|
Loading…
Reference in New Issue
Block a user