dev.harrel.jsonschema.providers.JettisonNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema Show documentation
Show all versions of json-schema Show documentation
Library for JSON schema validation
The newest version!
package dev.harrel.jsonschema.providers;
import dev.harrel.jsonschema.JsonNode;
import dev.harrel.jsonschema.JsonNodeFactory;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONTokener;
import java.util.*;
public final class JettisonNode extends SimpleJsonNode {
private JettisonNode(Object node, String jsonPointer) {
super(Objects.requireNonNull(node), jsonPointer);
}
public JettisonNode(Object node) {
this(node, "");
}
@Override
public boolean asBoolean() {
return (Boolean) node;
}
@Override
public String asString() {
return Objects.toString(isNull() ? null : node);
}
@Override
List createArray() {
JSONArray arrayNode = (JSONArray) node;
List elements = new ArrayList<>(arrayNode.length());
for (int i = 0; i < arrayNode.length(); ++i) {
elements.add(new JettisonNode(arrayNode.opt(i), jsonPointer + "/" + elements.size()));
}
return elements;
}
@Override
@SuppressWarnings("unchecked")
Map createObject() {
JSONObject jsonObject = (JSONObject) node;
Map map = MapUtil.newHashMap(jsonObject.length());
for (Object object : jsonObject.toMap().entrySet()) {
Map.Entry