1 package net.pterodactylus.sone.utils
3 import com.fasterxml.jackson.databind.JsonNode
4 import com.fasterxml.jackson.databind.node.ArrayNode
5 import com.fasterxml.jackson.databind.node.JsonNodeFactory.instance
6 import com.fasterxml.jackson.databind.node.ObjectNode
8 fun jsonObject(block: ObjectNode.() -> Unit): ObjectNode = ObjectNode(instance).apply(block)
10 fun jsonObject(vararg properties: Pair<String, Any?>) = jsonObject {
12 it.second.let { value ->
14 is String -> put(it.first, value)
15 is Int -> put(it.first, value)
16 is Long -> put(it.first, value)
17 is Boolean -> put(it.first, value)
24 fun jsonArray(vararg objects: String?): ArrayNode = objects.fold(ArrayNode(instance), ArrayNode::add)
25 fun jsonArray(vararg objects: JsonNode?): ArrayNode = objects.fold(ArrayNode(instance), ArrayNode::add)
27 fun Iterable<ObjectNode>.toArray(): ArrayNode = fold(ArrayNode(instance), ArrayNode::add)