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


Java SchemaLoader.load方法代码示例

本文整理汇总了Java中org.everit.json.schema.loader.SchemaLoader.load方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaLoader.load方法的具体用法?Java SchemaLoader.load怎么用?Java SchemaLoader.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.everit.json.schema.loader.SchemaLoader的用法示例。


在下文中一共展示了SchemaLoader.load方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
public static void main(final String[] args) {
  JSONObject root = new JSONObject(
      new JSONTokener(EveritPerf.class.getResourceAsStream("/perftest.json")));
  JSONObject schemaObject = new JSONObject(
      new JSONTokener(EveritPerf.class.getResourceAsStream("/schema-draft4.json")));
  Schema schema = SchemaLoader.load(schemaObject);
  JSONObject subjects = root.getJSONObject("schemas");
  String[] names = JSONObject.getNames(subjects);
  System.out.println("Now test overit...");
  long startAt = System.currentTimeMillis();
  for (int i = 0; i < 500; ++i) {
    for (String subjectName : names) {
      JSONObject subject = (JSONObject) subjects.get(subjectName);
      schema.validate(subject);
    }
    if (i % 20 == 0) {
      System.out
          .println("Iteration " + i + " (in " + (System.currentTimeMillis() - startAt) + "ms)");
    }
  }
  long endAt = System.currentTimeMillis();
  long execTime = endAt - startAt;
  System.out.println("total time: " + execTime + " ms");

}
 
开发者ID:networknt,项目名称:json-schema-validator-perftest,代码行数:26,代码来源:EveritPerf.java

示例2: checkJsonSchemaCompatibility

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
@Test
public void checkJsonSchemaCompatibility() throws Exception {
    final JSONArray testCases = new JSONArray(
            readFile("org/zalando/nakadi/validation/invalid-schema-evolution-examples.json"));

    for(final Object testCaseObject : testCases) {
        final JSONObject testCase = (JSONObject) testCaseObject;
        final Schema original = SchemaLoader.load(testCase.getJSONObject("original_schema"));
        final Schema update = SchemaLoader.load(testCase.getJSONObject("update_schema"));
        final List<String> errorMessages = testCase
                .getJSONArray("errors")
                .toList()
                .stream()
                .map(Object::toString)
                .collect(toList());
        final String description = testCase.getString("description");

        assertThat(description, service.collectChanges(original, update).stream()
                .map(change -> change.getType().toString() + " " + change.getJsonPath())
                .collect(toList()), is(errorMessages));

    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:24,代码来源:SchemaDiffTest.java

示例3: validate

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
/**
 * Validates a given JSON Object against the a given profile schema.
 * @param jsonObjectToValidate
 * @param profileId
 * @throws DataPackageException
 * @throws ValidationException 
 */
public void validate(JSONObject jsonObjectToValidate, String profileId) throws DataPackageException, ValidationException{ 

    InputStream inputStream = Validator.class.getResourceAsStream("/schemas/" + profileId + ".json");
    if(inputStream != null){
        JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
        Schema schema = SchemaLoader.load(rawSchema);
        schema.validate(jsonObjectToValidate); // throws a ValidationException if this object is invalid
        
    }else{
        throw new DataPackageException("Invalid profile id: " + profileId);
    }
    
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:21,代码来源:Validator.java

示例4: schemaFromFile

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
/**
 * Create JSON Schema object from json schema file
 *
 * @param jsonFile JSON file containing the schema
 * @return Schema JSON schema object used to validate corresponding json data against
 * @see <a href="https://github.com/everit-org/json-schema" target="_blank">Schema</a>
 */
public static Schema schemaFromFile(final String jsonFile) throws IOException {
	File file = new File(jsonFile);
	String jsonStr = FileUtils.readFileToString(file, Charset.defaultCharset());
	JSONObject schemaObject = new JSONObject(jsonStr);
	Schema jsonSchema = SchemaLoader.load(schemaObject);

	return jsonSchema;
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:16,代码来源:BaseUtil.java

示例5: schemaFromResource

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
/**
 * Create JSON Schema object from json schema resource
 *
 * @param resource JSON resource file containing the schema
 * @return Schema JSON schema object used to validate corresponding json data against
 * @see <a href="https://github.com/everit-org/json-schema" target="_blank">Schema</a>
 */
public static Schema schemaFromResource(final String resource) throws IOException {
	String jsonStr = IOUtils.resourceToString(resource, Charset.defaultCharset());
	JSONObject schemaObject = new JSONObject(jsonStr);
	Schema jsonSchema = SchemaLoader.load(schemaObject);

	return jsonSchema;
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:15,代码来源:BaseUtil.java

示例6: validate

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
public static void validate(String schema, String input){
	JSONObject jsonSchema = new JSONObject(schema);
	JSONObject jsonSubject = new JSONObject(input);
	
    Schema schema_ = SchemaLoader.load(jsonSchema);
    schema_.validate(jsonSubject);
}
 
开发者ID:denkbar,项目名称:step,代码行数:8,代码来源:JsonSchemaValidator.java

示例7: setUp

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
    final List<SchemaEvolutionConstraint> evolutionConstraints= Lists.newArrayList(evolutionConstraint);
    final JSONObject metaSchemaJson = new JSONObject(Resources.toString(Resources.getResource("schema.json"),
            Charsets.UTF_8));
    final Schema metaSchema = SchemaLoader.load(metaSchemaJson);
    this.service = new SchemaEvolutionService(metaSchema, evolutionConstraints, schemaDiff, compatibleChanges,
            forwardChanges, errorMessages);

    Mockito.doReturn("error").when(errorMessages).get(any());
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:12,代码来源:SchemaEvolutionServiceTest.java

示例8: load

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
private Schema load(
        String schemaStoreDb,
        BsonValue schemaId)
        throws JsonSchemaNotFoundException {
    BsonDocument document = loadRaw(schemaStoreDb, schemaId);

    return SchemaLoader.load(
            new JSONObject(document.toJson()), new SchemaStoreClient());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:10,代码来源:JsonSchemaCacheSingleton.java

示例9: loadSchema

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
/**
 * Loads JSON schema.
 * The schema may contain remote references.
 *
 * @param schema String containing the JSON schema to load
 * @return loaded {@link Schema}
 * @throws MolgenisDataException if the schema fails to load
 */
public Schema loadSchema(String schema)
{
	try
	{
		JSONObject rawSchema = new JSONObject(new JSONTokener(schema));
		return SchemaLoader.load(rawSchema);
	}
	catch (JSONException | SchemaException e)
	{
		throw new MolgenisDataException("Failed to load JSON schema", e);
	}
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:21,代码来源:JsonValidator.java

示例10: initValidator

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
private void initValidator(){
    // Init for validation
    InputStream tableSchemaInputStream = TypeInferrer.class.getResourceAsStream("/schemas/table-schema.json");
    JSONObject rawTableJsonSchema = new JSONObject(new JSONTokener(tableSchemaInputStream));
    this.tableJsonSchema = SchemaLoader.load(rawTableJsonSchema);
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:7,代码来源:Schema.java

示例11: whenSchemaGenerated

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
private void whenSchemaGenerated() {
    schemaString = generator.generateSchema(fieldDescriptors);
    schema = SchemaLoader.load(new JSONObject(schemaString));
}
 
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:5,代码来源:JsonSchemaFromFieldDescriptorsGeneratorTest.java

示例12: schema

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
private Schema schema(final EventTypeBase eventType) {
    final JSONObject schemaAsJson = new JSONObject(eventType.getSchema().getSchema());

    return SchemaLoader.load(schemaAsJson);
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:6,代码来源:SchemaEvolutionService.java

示例13: schemaEvolutionService

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
@Bean
public SchemaEvolutionService schemaEvolutionService() throws IOException {
    final JSONObject metaSchemaJson = new JSONObject(Resources.toString(Resources.getResource("schema.json"),
            Charsets.UTF_8));
    final Schema metaSchema = SchemaLoader.load(metaSchemaJson);

    final List<SchemaEvolutionConstraint> schemaEvolutionConstraints = Lists.newArrayList(
            new CategoryChangeConstraint(),
            new CompatibilityModeChangeConstraint(),
            new PartitionKeyFieldsConstraint(),
            new PartitionStrategyConstraint(),
            new EnrichmentStrategyConstraint()
    );

    final Map<SchemaChange.Type, Version.Level> compatibleChanges = new HashMap<>();
    compatibleChanges.put(DESCRIPTION_CHANGED, PATCH);
    compatibleChanges.put(TITLE_CHANGED, PATCH);
    compatibleChanges.put(PROPERTIES_ADDED, MINOR);
    compatibleChanges.put(ID_CHANGED, MAJOR);
    compatibleChanges.put(SCHEMA_REMOVED, MAJOR);
    compatibleChanges.put(TYPE_CHANGED, MAJOR);
    compatibleChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
    compatibleChanges.put(PROPERTY_REMOVED, MAJOR);
    compatibleChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
    compatibleChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
    compatibleChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
    compatibleChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
    compatibleChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
    compatibleChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(REQUIRED_ARRAY_EXTENDED, MAJOR);
    compatibleChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
    compatibleChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);

    final Map<SchemaChange.Type, Version.Level> forwardChanges = new HashMap<>();
    forwardChanges.put(DESCRIPTION_CHANGED, PATCH);
    forwardChanges.put(TITLE_CHANGED, PATCH);
    forwardChanges.put(PROPERTIES_ADDED, MINOR);
    forwardChanges.put(REQUIRED_ARRAY_EXTENDED, MINOR);
    forwardChanges.put(ID_CHANGED, MAJOR);
    forwardChanges.put(SCHEMA_REMOVED, MAJOR);
    forwardChanges.put(TYPE_CHANGED, MAJOR);
    forwardChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
    forwardChanges.put(PROPERTY_REMOVED, MAJOR);
    forwardChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
    forwardChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
    forwardChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
    forwardChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
    forwardChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
    forwardChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
    forwardChanges.put(ADDITIONAL_PROPERTIES_NARROWED, MINOR);
    forwardChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);

    final Map<SchemaChange.Type, String> errorMessage = new HashMap<>();
    errorMessage.put(SCHEMA_REMOVED, "change not allowed");
    errorMessage.put(TYPE_CHANGED, "schema types must be the same");
    errorMessage.put(NUMBER_OF_ITEMS_CHANGED, "the number of schema items cannot be changed");
    errorMessage.put(PROPERTY_REMOVED, "schema properties cannot be removed");
    errorMessage.put(DEPENDENCY_ARRAY_CHANGED, "schema dependencies array cannot be changed");
    errorMessage.put(DEPENDENCY_SCHEMA_CHANGED, "schema dependencies cannot be changed");
    errorMessage.put(COMPOSITION_METHOD_CHANGED, "schema composition method changed");
    errorMessage.put(ATTRIBUTE_VALUE_CHANGED, "change to attribute value not allowed");
    errorMessage.put(ENUM_ARRAY_CHANGED, "enum array changed");
    errorMessage.put(SUB_SCHEMA_CHANGED, "sub schema changed");
    errorMessage.put(DEPENDENCY_SCHEMA_REMOVED, "dependency schema removed");
    errorMessage.put(REQUIRED_ARRAY_CHANGED, "required array changed");
    errorMessage.put(REQUIRED_ARRAY_EXTENDED, "required array changed");
    errorMessage.put(ADDITIONAL_PROPERTIES_CHANGED, "change not allowed");
    errorMessage.put(ADDITIONAL_PROPERTIES_NARROWED, "change not allowed");
    errorMessage.put(ADDITIONAL_ITEMS_CHANGED, "change not allowed");

    final SchemaDiff diff = new SchemaDiff();

    return new SchemaEvolutionService(metaSchema, schemaEvolutionConstraints, diff, compatibleChanges,
            forwardChanges, errorMessage);
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:81,代码来源:ValidatorConfig.java

示例14: schemaFromString

import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
/**
 * Create JSON Schema object from json schema string
 *
 * @param jsonStr JSON string representing the schema
 * @return Schema JSON schema object used to validate corresponding json data against
 * @see <a href="https://github.com/everit-org/json-schema" target="_blank">Schema</a>
 */
public static Schema schemaFromString(final String jsonStr) {
	JSONObject schemaObject = new JSONObject(jsonStr);
	Schema jsonSchema = SchemaLoader.load(schemaObject);

	return jsonSchema;
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:14,代码来源:BaseUtil.java


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