当前位置: 首页>>代码示例>>Java>>正文


Java JsonValidator类代码示例

本文整理汇总了Java中com.github.fge.jsonschema.main.JsonValidator的典型用法代码示例。如果您正苦于以下问题:Java JsonValidator类的具体用法?Java JsonValidator怎么用?Java JsonValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonValidator类属于com.github.fge.jsonschema.main包,在下文中一共展示了JsonValidator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDefaultConfig

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
@Test
public final void testDefaultConfig()
throws Exception {
	final ObjectMapper m = new ObjectMapper()
		.configure(JsonParser.Feature.ALLOW_COMMENTS, true)
		.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
	final JsonNode jsonInput = m.readTree(
		Paths.get(PathUtil.getBaseDir(), "config", "defaults.json").toFile()
	);
	final JsonNode jsonSchema = m.readTree(
		Paths.get(PathUtil.getBaseDir(), "config", "config-schema.json").toFile()
	);
	final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
	final JsonValidator validator = factory.getValidator();
	final ProcessingReport report = validator.validate(jsonSchema, jsonInput);
	assertTrue(report.toString(), report.isSuccess());
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:18,代码来源:ValidateConfigTest.java

示例2: validate

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:15,代码来源:BaseComponentDescriptorService.java

示例3: testAllScenarios

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
@Test
public final void testAllScenarios()
throws Exception {

	final ObjectMapper m = new ObjectMapper()
		.configure(JsonParser.Feature.ALLOW_COMMENTS, true)
		.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
	final JsonNode jsonSchema = m.readTree(
		Paths.get(PathUtil.getBaseDir(), DIR_EXAMPLE_SCENARIO, "json", "schema.json").toFile()
	);
	final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
	final JsonValidator validator = factory.getValidator();

	final List<Path> scenarioPaths = Files
		.walk(Paths.get(PathUtil.getBaseDir(), DIR_EXAMPLE_SCENARIO, "json"))
		.filter(path -> path.toString().endsWith(".json"))
		.filter(path -> !path.endsWith("schema.json") && !path.endsWith("invalid.json"))
		.collect(Collectors.toList());

	JsonNode nextScenario;
	ProcessingReport report;
	for(final Path nextScenarioPath : scenarioPaths) {
		if(!nextScenarioPath.toString().contains("compat")) {
			System.out.println("Validating the scenario file: " + nextScenarioPath.toString());
			nextScenario = m.readTree(nextScenarioPath.toFile());
			report = validator.validate(jsonSchema, nextScenario);
			assertTrue(report.toString(), report.isSuccess());
		}
	}
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:31,代码来源:ValidateScenariosTest.java

示例4: validateJson

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
protected void validateJson(String jsonFileName) throws IOException, ProcessingException, JsonLdError {

        JsonNode schema = getSchema();
        assertNotNull(schema);

        String jsonStr = getJson(jsonFileName);
        assertNotNull(jsonStr);

        Object jsonObj = JsonUtils.fromString(jsonStr);
        List<Object> expandedJson = JsonLdProcessor.expand(jsonObj);
        jsonStr = JsonUtils.toString(expandedJson);
        JsonNode json = JsonLoader.fromString(jsonStr);

        JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator();
        ProcessingReport processingReport = jsonValidator.validate(schema, json);
        assertNotNull(processingReport);
        if (!processingReport.isSuccess()) {

            ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
            assertNotNull(jsonArray);

            Iterator<ProcessingMessage> iterator = processingReport.iterator();
            while (iterator.hasNext()) {
                ProcessingMessage processingMessage = iterator.next();
                jsonArray.add(processingMessage.asJson());
            }

            String errorJson = JsonUtils.toPrettyString(jsonArray);
            assertNotNull(errorJson);

            fail(errorJson);
        }
    }
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:34,代码来源:AbstractSchemaValidatorTest.java

示例5: validateJsonData

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
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");
}
 
开发者ID:apache,项目名称:metron,代码行数:12,代码来源:CEFParserTest.java

示例6: validate

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
protected String validate(String jsonStr, JsonNode validationSchema) throws ProcessingException, IOException {

        JsonNode json = JsonLoader.fromString(jsonStr);

        JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator();
        ProcessingReport processingReport = jsonValidator.validate(validationSchema, json);
        if (!processingReport.isSuccess()) {

            ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();

            for (ProcessingMessage processingMessage : processingReport) {
                jsonArray.add(processingMessage.asJson());
            }

            return JsonUtils.toPrettyString(jsonArray);
        }

        return null;
    }
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:20,代码来源:AbstractMessageConverter.java

示例7: validateJsonData

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
/**
 * validateJsonData
 * @param jsonSchema
 * @param jsonData
 * @return
 * @throws Exception
 */
 
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);
    System.out.println(report);
    
    return report.toString().contains("success");
}
 
开发者ID:OpenSOC,项目名称:opensoc-streaming,代码行数:23,代码来源:AbstractConfigTest.java

示例8: validateJsonData

import com.github.fge.jsonschema.main.JsonValidator; //导入依赖的package包/类
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");
}
 
开发者ID:apache,项目名称:metron,代码行数:14,代码来源:AbstractParserConfigTest.java


注:本文中的com.github.fge.jsonschema.main.JsonValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。