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

tech.harmonysoft.oss.json.JsonApi.kt Maven / Gradle / Ivy

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