com.ancientlightstudios.quarkus.kotlin.openapi.UnsafeJson.kt Maven / Gradle / Ivy
package com.ancientlightstudios.quarkus.kotlin.openapi
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.ObjectNode
class UnsafeJson(val value: JsonNode) {
fun modifyObject(block: ObjectNode.() -> ObjectNode) = when (value) {
is ObjectNode -> UnsafeJson(value.run(block))
else -> throw IllegalStateException("object node expected")
}
fun modifyArray(block: ArrayNode.() -> ArrayNode) = when (value) {
is ArrayNode -> UnsafeJson(value.run(block))
else -> throw IllegalStateException("array node expected")
}
}