1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 00:03:48 +00:00

KtorRequestsExecutor custom json formatter

This commit is contained in:
InsanusMokrassar 2019-02-05 12:30:09 +08:00
parent b0f7563191
commit 6f04baea4e
2 changed files with 5 additions and 2 deletions

View File

@ -29,6 +29,8 @@ must be regular text
### 0.9.3
* `KtorRequestsExecutor` now can use custom `JSON` string formatter (by default - non strict)
### 0.8.5
* Add extension `String#toMarkdown`

View File

@ -22,7 +22,8 @@ class KtorRequestsExecutor(
hostUrl: String = "https://api.telegram.org",
callsFactories: List<KtorCallFactory> = emptyList(),
excludeDefaultFactories: Boolean = false,
private val requestsLimiter: RequestLimiter = EmptyLimiter
private val requestsLimiter: RequestLimiter = EmptyLimiter,
private val jsonFormatter: JSON = JSON.nonstrict
) : BaseRequestsExecutor(token, hostUrl) {
constructor(
token: String,
@ -59,7 +60,7 @@ class KtorRequestsExecutor(
throw IllegalArgumentException("Can't execute request: $request")
}
val content = call.response.content.toByteArray().toString(Charset.defaultCharset())
val responseObject = JSON.parse(
val responseObject = jsonFormatter.parse(
ResponseParameters.serializer(request.resultSerializer()),
content
)