mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
extension was added
This commit is contained in:
parent
0de1d9cfda
commit
be5b3745b9
@ -53,6 +53,8 @@
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* Currently `UpdateDeserializationStrategy` is publicly available
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Extension `asTelegramUpdate` was added
|
||||
|
||||
### 0.27.2
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
||||
internal val nonstrictJsonFormat = Json {
|
||||
isLenient = true
|
||||
ignoreUnknownKeys = true
|
||||
serializeSpecialFloatingPointValues = true
|
||||
useArrayPolymorphism = true
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.nonstrictJsonFormat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateDeserializationStrategy
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
/**
|
||||
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||
*/
|
||||
fun Json.asTelegramUpdate(source: String) = parse(UpdateDeserializationStrategy, source)
|
||||
/**
|
||||
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||
*/
|
||||
fun Json.asTelegramUpdate(source: JsonElement) = fromJson(UpdateDeserializationStrategy, source)
|
||||
|
||||
/**
|
||||
* @return Deserialize [this] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]. In fact,
|
||||
* it is must be JSON
|
||||
*
|
||||
* @see Json.asTelegramUpdate
|
||||
*/
|
||||
fun String.asTelegramUpdate() = nonstrictJsonFormat.asTelegramUpdate(this)
|
||||
/**
|
||||
* @return Deserialize [this] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||
*
|
||||
* @see Json.asTelegramUpdate
|
||||
*/
|
||||
fun JsonElement.asTelegramUpdate() = nonstrictJsonFormat.asTelegramUpdate(this)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user