getJsonElement

fun getJsonElement(value: Any?, requireTokenization: (Any?) -> Boolean? = null): JsonElement

Get a KotlinX JsonElement for any Kotlin/JVM value or instance.

Return

Input value unchanged if value is already a JsonElement, otherwise JsonElement best representing value— Generally best effort to create JsonObject, JsonArray, JsonPrimitive, or JsonNull directly from value, and token string JsonPrimitive if best effort fails or tokenization is mandatory for the given value.

Parameters

value

Any Kotlin/JVM value or instance to turn into a JsonElement.

requireTokenization

If given, a function that returns whether the value must be tokenized even if it can be serialized.

Sources

jvm source
Link copied to clipboard