Close response properly in core
utility parseAs()
(#9591)
This commit is contained in:
parent
603fd58fff
commit
2142cb32c2
@ -10,19 +10,19 @@ import uy.kohesive.injekt.injectLazy
|
||||
val jsonInstance: Json by injectLazy()
|
||||
|
||||
/**
|
||||
* Parses and serializes the String as the type <T>.
|
||||
* Parses JSON string into an object of type [T].
|
||||
*/
|
||||
inline fun <reified T> String.parseAs(json: Json = jsonInstance): T =
|
||||
json.decodeFromString(this)
|
||||
|
||||
/**
|
||||
* Parse and serialize the response body as the type <T>.
|
||||
* Parses the response body into an object of type [T].
|
||||
*/
|
||||
inline fun <reified T> Response.parseAs(json: Json = jsonInstance): T =
|
||||
json.decodeFromStream(body.byteStream())
|
||||
use { json.decodeFromStream(body.byteStream()) }
|
||||
|
||||
/**
|
||||
* Serializes the object to a JSON String.
|
||||
* Serializes the object to a JSON string.
|
||||
*/
|
||||
inline fun <reified T> T.toJsonString(json: Json = jsonInstance): String =
|
||||
json.encodeToString(this)
|
||||
|
Loading…
x
Reference in New Issue
Block a user