org.stellar.walletsdk.json.Json.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wallet-sdk Show documentation
Show all versions of wallet-sdk Show documentation
Kotlin Stellar Wallet SDK
The newest version!
package org.stellar.walletsdk.json
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import okhttp3.Response
private val log = KotlinLogging.logger {}
internal val defaultJson = Json { ignoreUnknownKeys = true }
internal inline fun String.fromJson(format: Json = defaultJson): T {
log.trace { "JSON format: $this" }
return format.decodeFromString(this)
}
internal inline fun Response.toJson(format: Json = defaultJson): T {
return this.body!!.string().fromJson(format)
}
internal inline fun T.toJson(format: Json = defaultJson): String {
return format.encodeToString(this)
}