本文整理汇总了Java中com.github.fge.jackson.JsonLoader.fromResource方法的典型用法代码示例。如果您正苦于以下问题:Java JsonLoader.fromResource方法的具体用法?Java JsonLoader.fromResource怎么用?Java JsonLoader.fromResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.fge.jackson.JsonLoader
的用法示例。
在下文中一共展示了JsonLoader.fromResource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _validate
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
protected ProcessingReport _validate(JsonNode json) throws IOException {
final JsonNode belSchema = JsonLoader.fromResource("/bel-json-graph.schema.json");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema;
try {
schema = factory.getJsonSchema(belSchema);
return schema.validate(json, true);
} catch (ProcessingException e) {
throw new IOException(e);
}
}
示例2: GenericOpenRtbValidator
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
/**
* Constructs a JSON validator using the given schema read as a resource.
*
* @param schemaResource
* the schema resource
*/
GenericOpenRtbValidator(String schemaResource) {
try {
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonNode jsonNode = JsonLoader.fromResource(schemaResource);
schema = factory.getJsonSchema(jsonNode);
} catch (IOException | ProcessingException e) {
throw new IllegalStateException("could not initialize validator due to previous exception", e);
}
}
示例3: main
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public static void main(final String... args)
throws IOException, ProcessingException
{
final JsonNode googleAPI
= JsonLoader.fromResource("/perftest.json");
final Map<String, JsonNode> googleSchemas
= JacksonUtils.asMap(googleAPI.get("schemas"));
long begin, current;
begin = System.currentTimeMillis();
doValidate(googleSchemas, -1);
current = System.currentTimeMillis();
System.out.println("Initial validation :" + (current - begin) + " ms");
begin = System.currentTimeMillis();
for (int i = 0; i < 500; i++) {
doValidate(googleSchemas, i);
if (i % 20 == 0) {
current = System.currentTimeMillis();
System.out.println(String.format("Iteration %d (in %d ms)", i,
current - begin));
}
}
final long end = System.currentTimeMillis();
System.out.println("END -- time in ms: " + (end - begin));
System.exit(0);
}
示例4: validate
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
private void validate(String schemaPath, String filePath) throws IOException, ProcessingException {
JsonNode schema = JsonLoader.fromResource(schemaPath);
JsonNode json = JsonLoader.fromPath(filePath);
com.github.fge.jsonschema.main.JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
ProcessingReport report = validator.validate(schema, json);
if ((report == null) || !report.isSuccess()) {
logger.error("Invalid JSON");
if (report != null) {
throw new ProcessingException(report.toString());
} else {
throw new ProcessingException("JSON validation report is null for " + filePath);
}
}
}
示例5: testGetJsonValidation
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
@Test
public void testGetJsonValidation() throws Exception {
MathTag tag = new MathTag(1, "a+b", WikiTextUtils.MathMarkUpType.LATEX);
final String real = "[" + tag.toJson() + "]";
final JsonNode jsonSchema = JsonLoader.fromResource("/formula_list_schema.json");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(jsonSchema);
ProcessingReport report = schema.validate(JsonLoader.fromString(real));
assertTrue(report.isSuccess());
}
示例6: getJsonNodeFromResource
import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public static JsonNode getJsonNodeFromResource(String resource)
throws IOException
{
return JsonLoader.fromResource(resource);
}