xpertss.json.schema.keyword.digest.draftv4.RequiredDigester 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
A Java implementation of the JSON Schema specification.
The newest version!
package xpertss.json.schema.keyword.digest.draftv4;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.fge.jackson.NodeType;
import xpertss.json.schema.keyword.digest.AbstractDigester;
import xpertss.json.schema.keyword.digest.Digester;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Digester for {@code required}
*
* Its role is simply enough to ensure that, for instance, {@code
* ["a", "b"]} and {@code ["b", "a"]} produce the same output.
*/
public final class RequiredDigester extends AbstractDigester {
private static final Digester INSTANCE = new RequiredDigester();
public static Digester getInstance()
{
return INSTANCE;
}
private RequiredDigester()
{
super("required", NodeType.OBJECT);
}
@Override
public JsonNode digest(JsonNode schema)
{
ObjectNode ret = FACTORY.objectNode();
ArrayNode required = FACTORY.arrayNode();
ret.put(keyword, required);
List list = Lists.newArrayList(schema.get(keyword));
Collections.sort(list, Comparator.comparing(JsonNode::textValue));
required.addAll(list);
return ret;
}
}