本文整理匯總了Java中com.github.fge.jsonschema.core.report.ProcessingReport.isSuccess方法的典型用法代碼示例。如果您正苦於以下問題:Java ProcessingReport.isSuccess方法的具體用法?Java ProcessingReport.isSuccess怎麽用?Java ProcessingReport.isSuccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.fge.jsonschema.core.report.ProcessingReport
的用法示例。
在下文中一共展示了ProcessingReport.isSuccess方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isValid
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
public static boolean isValid(String json, String schema) throws Exception {
JsonNode schemaNode = JsonLoader.fromString(schema);
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonSchema jsonSchema = factory.getJsonSchema(schemaNode);
JsonNode jsonNode = JsonLoader.fromString(json);
ProcessingReport report = jsonSchema.validate(jsonNode);
logger.debug("report: {}", report);
return report.isSuccess();
}
示例2: isValid
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
public boolean isValid(JsonNode jsonNode) {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
log.verboseOutput("Checking against schema. Available at 'https://raw.githubusercontent.com/pivio/pivio-client/master/src/main/resources/pivio-schema.json'.", configuration.isVerbose());
try {
String schemaContent = readFromJARFile("/pivio-schema.json");
JsonNode schemaNode = new ObjectMapper().readTree(schemaContent);
final JsonSchema jsonSchema = factory.getJsonSchema(schemaNode);
ProcessingReport processingReport = jsonSchema.validate(jsonNode);
for (ProcessingMessage processingMessage : processingReport) {
String pointer = processingMessage.asJson().get("instance").get("pointer").asText();
log.output(pointer + " : " + processingMessage.getMessage());
}
return processingReport.isSuccess();
} catch (ProcessingException | IOException e ) {
log.output("Error processing Json. "+e.getMessage());
return false;
}
}
示例3: doValidate
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
private static void doValidate(final Map<String, JsonNode> schemas,
final int i)
throws ProcessingException
{
String name;
JsonNode value;
ProcessingReport report;
for (final Map.Entry<String, JsonNode> entry: schemas.entrySet()) {
name = entry.getKey();
value = entry.getValue();
report = SCHEMA.validate(value);
if (!report.isSuccess()) {
System.err.println("ERROR: schema " + name + " did not "
+ "validate (iteration " + i + ')');
System.exit(1);
}
}
}
示例4: execute
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
@Override
protected ExecuteResult execute(final WebServiceConnector connector) {
final String body = connector.getBody();
final ObjectMapper mapper = new ObjectMapper();
try {
final JsonNode obj = mapper.readTree(body);
final JsonNode schema = mapper.readTree(this.schema);
final ProcessingReport report = JsonSchemaFactory.byDefault()
.getJsonSchema(schema)
.validate(obj);
return report.isSuccess() ? getSuccessOutput() : getFailedOutput();
} catch (IOException | ProcessingException e) {
return getFailedOutput();
}
}
示例5: validate
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
public ValidationErrors validate(String schema, String requestBody) {
ValidationErrors errors = new ValidationErrors();
try {
JsonNode schemaNode = JsonLoader.fromString(schema);
JsonNode dataNode = JsonLoader.fromString(requestBody);
ProcessingReport report = JsonSchemaFactory.byDefault().getJsonSchema(schemaNode).validate(dataNode);
if (!report.isSuccess())
report.iterator().forEachRemaining(m -> errors.addMessage("[ %s ] [ body ] %s", bodyType, m.getMessage()));
} catch (Exception e) {
errors.addMessage("[ %s ] [ body ] Unexpected error of [ %s ] while validating JSON content", bodyType, e.getMessage());
}
return errors;
}
示例6: validate
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
public void validate(JsonNode node) throws InvalidJsonException {
ProcessingReport report = null;
try {
report = getSchema().validate(node);
}
catch (Throwable ex) {
throw new InvalidJsonException("Could not validate JSON against schema" + getDescriptionAppendable(), ex);
}
if (!report.isSuccess()) {
StringBuilder builder = new StringBuilder();
builder.append("Could not validate JSON against schema");
builder.append(getDescriptionAppendable());
builder.append(":");
builder.append(LS);
List<ProcessingMessage> messages = Lists.newArrayList(report);
for (int i = 0; i < messages.size(); i++) {
builder.append("- ");
builder.append(messages.get(i).getMessage());
builder.append(i == (messages.size() - 1) ? EMPTY : LS);
}
throw new InvalidJsonException(builder.toString());
}
}
示例7: validatingRead
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public GraphsWithValidation validatingRead(File input) throws IOException {
if (input == null) throw new NullPointerException("input cannot be null");
if (!input.exists()) throw new FileNotFoundException("input does not exist");
if (!input.exists() || !input.canRead())
throw new FileNotFoundException("input does not exist");
JsonNode json = _readJSON(new FileInputStream(input));
ProcessingReport report = _validate(json);
if (report.isSuccess()) {
return new GraphsWithValidation(_readGraph(json), report);
}
return new GraphsWithValidation(new Graph[0], report);
}
示例8: validateSchema
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
private JsonSchema validateSchema(JsonNode jsonSchema)
throws UnRAVLException {
try {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(jsonSchema);
SyntaxValidator syntaxValidator = factory.getSyntaxValidator();
if (!syntaxValidator.schemaIsValid(jsonSchema)) {
throw new UnRAVLException("JSON schema is invalid");
}
ProcessingReport report = syntaxValidator
.validateSchema(jsonSchema);
boolean success = report.isSuccess();
if (!success) {
throw new UnRAVLAssertionException(report.toString());
}
return schema;
} catch (ProcessingException e) {
throw new UnRAVLException(e);
}
}
示例9: loadSchema
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
/**
* Load a schema from given resourceName.
*
* @param resourceName
* @return the schema
* @throws ProcessingException
* @throws IOException
*/
public static JsonSchema loadSchema(String resourceName) throws ProcessingException, IOException {
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
SyntaxValidator validator = factory.getSyntaxValidator();
JsonNode node = loadJsonNode(resourceName);
ProcessingReport report = validator.validateSchema(node);
if (!report.isSuccess()) {
throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
}
JsonSchema schema = factory.getJsonSchema("resource:/" + resourceName);
if (null == schema) {
throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
}
return schema;
}
示例10: jsonSchemaValidation
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
/**
* Validates input node against given schema. Returns NULL if no errors
* reported, else returns string representing violations.
*
* @param schema the json schema (see #loadSchema)
* @param node the json node to validate
* @return null if there are no errors, else string with all errors and
* warnings
* @throws ProcessingException
*/
public static String jsonSchemaValidation(JsonSchema schema, JsonNode node) throws ProcessingException, JsonProcessingException {
ProcessingReport report = schema.validate(node);
Iterator<ProcessingMessage> i = report.iterator();
StringBuilder buff = new StringBuilder();
while (!report.isSuccess() && i != null && i.hasNext()) {
ProcessingMessage pm = i.next();
// attempting to pretty print the json
ObjectMapper mapper = new ObjectMapper();
String prettyPrintJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(pm.asJson());
buff.append(prettyPrintJson).append("\n\n");
}
return report.isSuccess() ? null : buff.toString();
}
示例11: buildResult
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
@Override
protected JsonNode buildResult(final String input)
throws IOException
{
final ValueHolder<String> holder = ValueHolder.hold("source", input);
final ProcessingReport report = new ListProcessingReport();
final ProcessingResult<ValueHolder<SchemaTree>> result
= ProcessingResult.uncheckedResult(PROCESSOR, report, holder);
final ProcessingReport processingReport = result.getReport();
final ObjectNode ret = FACTORY.objectNode();
final boolean success = processingReport.isSuccess();
ret.put(VALID, success);
final JsonNode content = success
? result.getResult().getValue().getBaseNode()
: buildReport(result.getReport());
ret.put(RESULTS, JacksonUtils.prettyPrint(content));
return ret;
}
示例12: buildResult
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
private static JsonNode buildResult(final String rawSchema,
final String rawData)
throws IOException
{
final ObjectNode ret = JsonNodeFactory.instance.objectNode();
final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
rawSchema);
final boolean invalidData = fillWithData(ret, INPUT2, INVALID_INPUT2,
rawData);
final JsonNode schemaNode = ret.remove(INPUT);
final JsonNode data = ret.remove(INPUT2);
if (invalidSchema || invalidData)
return ret;
final ProcessingReport report
= VALIDATOR.validateUnchecked(schemaNode, data);
final boolean success = report.isSuccess();
ret.put(VALID, success);
final JsonNode node = ((AsJson) report).asJson();
ret.put(RESULTS, JacksonUtils.prettyPrint(node));
return ret;
}
示例13: buildResult
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
@Override
protected JsonNode buildResult(final String input)
throws IOException, ProcessingException
{
final ObjectNode ret = FACTORY.objectNode();
final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
input);
final JsonNode schemaNode = ret.remove(INPUT);
if (invalidSchema)
return ret;
final ProcessingReport report = VALIDATOR.validateSchema(schemaNode);
final boolean success = report.isSuccess();
ret.put(VALID, success);
ret.put(RESULTS, JacksonUtils.prettyPrint(buildReport(report)));
return ret;
}
示例14: isValid
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
@Override
public String isValid(String json) {
String validationResult = "";
if (!Strings.isNullOrEmpty(json)) {
try {
ProcessingReport processingReport = validator
.validate(
objectMapper.readTree(schema),
objectMapper.readTree(json),
true
);
if (!processingReport.isSuccess()) {
validationResult = formatProcessingReport(processingReport);
}
} catch (Exception e) {
mockServerLogger.info("Exception validating JSON", e);
return e.getClass().getSimpleName() + " - " + e.getMessage();
}
}
return validationResult;
}
示例15: valdate
import com.github.fge.jsonschema.core.report.ProcessingReport; //導入方法依賴的package包/類
@Override
public boolean valdate(final IActivityLogger aLogger,
final CJsonSchema aSchema, final JSONObject aData) throws Exception {
// validate json
try {
aLogger.logDebug(this, "getSchema",
"create JsonNode fro JSONObject for the data");
ObjectMapper wMapper = new ObjectMapper();
JsonNode wJson = wMapper.readTree(aData.toString());
aLogger.logDebug(this, "getSchema", "validate data with schema");
ProcessingReport wReport = aSchema.getSchema()
.validate(wJson, true);
if (wReport.isSuccess()) {
return true;
} else {
throw new SchemaException("ERROR; failed schema validation ! ["
+ wReport.toString() + "] ");
}
} catch (Exception e) {
throw new SchemaException(e, e.getMessage());
}
}