
tech.harmonysoft.oss.json.JsonApi.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harmonysoft-json-api Show documentation
Show all versions of harmonysoft-json-api Show documentation
Common general-purpose Kotlin utility
The newest version!
package tech.harmonysoft.oss.json
import kotlin.reflect.KClass
interface JsonApi {
fun parse(content: String, resultClass: KClass): T
fun parseJson(json: String): Any {
// it might be a regular json or json array, that's why we try to parse it as a map first and fallback to list
return try {
parse(json, Map::class)
} catch (_: Exception) {
try {
parse(json, List::class)
} catch (_: Exception) {
throw IllegalArgumentException("can't parse JSON from\n$json")
}
}
}
fun writeJson(json: Any): String
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy