Search in sources :

Example 1 with JsonValidator

use of com.github.fge.jsonschema.main.JsonValidator in project metron by apache.

the class AbstractParserConfigTest method validateJsonData.

protected boolean validateJsonData(final String jsonSchema, final String jsonData) throws IOException, ProcessingException {
    final JsonNode d = JsonLoader.fromString(jsonData);
    final JsonNode s = JsonLoader.fromString(jsonSchema);
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    JsonValidator v = factory.getValidator();
    ProcessingReport report = v.validate(s, d);
    return report.toString().contains("success");
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator)

Example 2 with JsonValidator

use of com.github.fge.jsonschema.main.JsonValidator in project metron by apache.

the class CEFParserTest method validateJsonData.

protected boolean validateJsonData(final String jsonSchema, final String jsonData) throws Exception {
    final JsonNode d = JsonLoader.fromString(jsonData);
    final JsonNode s = JsonLoader.fromString(jsonSchema);
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    JsonValidator v = factory.getValidator();
    ProcessingReport report = v.validate(s, d);
    return report.toString().contains("success");
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator)

Example 3 with JsonValidator

use of com.github.fge.jsonschema.main.JsonValidator in project thingsboard by thingsboard.

the class BaseComponentDescriptorService method validate.

@Override
public boolean validate(ComponentDescriptor component, JsonNode configuration) {
    JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
    try {
        if (!component.getConfigurationDescriptor().has("schema")) {
            throw new DataValidationException("Configuration descriptor doesn't contain schema property!");
        }
        JsonNode configurationSchema = component.getConfigurationDescriptor().get("schema");
        ProcessingReport report = validator.validate(configurationSchema, configuration);
        return report.isSuccess();
    } catch (ProcessingException e) {
        throw new IncorrectParameterException(e.getMessage(), e);
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)3 JsonValidator (com.github.fge.jsonschema.main.JsonValidator)3 JsonSchemaFactory (com.github.fge.jsonschema.main.JsonSchemaFactory)2 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1