diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt index 521b14e682..9745f0c2da 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt @@ -9,6 +9,8 @@ import kotlinx.serialization.internal.StringDescriptor import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObjectSerializer +private val formatter = Json.nonstrict + object PreviewChatSerializer : KSerializer { override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") @@ -18,10 +20,10 @@ object PreviewChatSerializer : KSerializer { val type = decodedJson.getPrimitive(typeField).content return when (type) { - "private" -> Json.nonstrict.fromJson(PrivateChatImpl.serializer(), decodedJson) - "group" -> Json.nonstrict.fromJson(GroupChatImpl.serializer(), decodedJson) - "supergroup" -> Json.nonstrict.fromJson(SupergroupChatImpl.serializer(), decodedJson) - "channel" -> Json.nonstrict.fromJson(ChannelChatImpl.serializer(), decodedJson) + "private" -> formatter.fromJson(PrivateChatImpl.serializer(), decodedJson) + "group" -> formatter.fromJson(GroupChatImpl.serializer(), decodedJson) + "supergroup" -> formatter.fromJson(SupergroupChatImpl.serializer(), decodedJson) + "channel" -> formatter.fromJson(ChannelChatImpl.serializer(), decodedJson) else -> throw IllegalArgumentException("Unknown type of chat") } } @@ -46,10 +48,10 @@ object ExtendedChatSerializer : KSerializer { val type = decodedJson.getPrimitive(typeField).content return when (type) { - "private" -> Json.nonstrict.fromJson(ExtendedPrivateChatImpl.serializer(), decodedJson) - "group" -> Json.nonstrict.fromJson(ExtendedGroupChatImpl.serializer(), decodedJson) - "supergroup" -> Json.nonstrict.fromJson(ExtendedSupergroupChatImpl.serializer(), decodedJson) - "channel" -> Json.nonstrict.fromJson(ExtendedChannelChatImpl.serializer(), decodedJson) + "private" -> formatter.fromJson(ExtendedPrivateChatImpl.serializer(), decodedJson) + "group" -> formatter.fromJson(ExtendedGroupChatImpl.serializer(), decodedJson) + "supergroup" -> formatter.fromJson(ExtendedSupergroupChatImpl.serializer(), decodedJson) + "channel" -> formatter.fromJson(ExtendedChannelChatImpl.serializer(), decodedJson) else -> throw IllegalArgumentException("Unknown type of chat") } }