xpertss.json.schema.processors.data.SchemaContext 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.processors.data;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.NodeType;
import xpertss.json.schema.core.report.MessageProvider;
import xpertss.json.schema.core.report.ProcessingMessage;
import xpertss.json.schema.core.tree.JsonTree;
import xpertss.json.schema.core.tree.SchemaTree;
import xpertss.json.schema.processors.digest.SchemaDigester;
import xpertss.json.schema.processors.validation.ValidationChain;
/**
* Input for both a {@link SchemaDigester} and a {@link ValidationChain}
*
* This is essentially a {@link FullData} which only retains the type of the
* instance to validate instead of the full instance.
*
* @see NodeType#getNodeType(JsonNode)
*/
public final class SchemaContext implements MessageProvider {
private final SchemaTree schema;
private final NodeType instanceType;
public SchemaContext(FullData data)
{
schema = data.getSchema();
final JsonTree tree = data.getInstance();
instanceType = tree != null
? NodeType.getNodeType(tree.getNode())
: null;
}
public SchemaContext(SchemaTree schema, NodeType instanceType)
{
this.schema = schema;
this.instanceType = instanceType;
}
public SchemaTree getSchema()
{
return schema;
}
public NodeType getInstanceType()
{
return instanceType;
}
@Override
public ProcessingMessage newMessage()
{
return new ProcessingMessage().put("schema", schema);
}
}