All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.stellar.walletsdk.json.Json.kt Maven / Gradle / Ivy

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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy