io.github.leinad75.maven.plugin.json.util.JsonTreeWalker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-validator-maven-plugin Show documentation
Show all versions of json-validator-maven-plugin Show documentation
Maven plugin to validate json files against a json schema
package io.github.leinad75.maven.plugin.json.util;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.util.function.BiConsumer;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.function.Consumer;
public class JsonTreeWalker {
public void walkTree(JsonNode root, Consumer consumer) {
walker(null, root, consumer);
}
private void walker(String nodename, JsonNode node, Consumer consumer) {
String nameToPrint = nodename != null ? nodename : "must_be_root";
if (node.isObject()) {
consumer.accept((ObjectNode) node);
node.fields().forEachRemaining(e -> walker(e.getKey(), e.getValue(), consumer));
} else if (node.isArray()) {
node.elements().forEachRemaining(n -> walker("array item of '" + nameToPrint + "'", n, consumer));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy