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


Java SchemaLoader类代码示例

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


SchemaLoader类属于org.everit.json.schema.loader包,在下文中一共展示了SchemaLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: validateGeoJsonSchema

import org.everit.json.schema.loader.SchemaLoader; //导入依赖的package包/类
/**
 * We only want to go through this initialization if we have to because it's a
 * performance issue the first time it is executed.
 * Because of this, so we don't include this logic in the constructor and only
 * call it when it is actually required after trying all other type inferral.
 * @param geoJson
 * @throws ValidationException 
 */
private void validateGeoJsonSchema(JSONObject geoJson) throws ValidationException{
    if(this.getGeoJsonSchema() == null){
        // FIXME: Maybe this infering against geojson scheme is too much.
        // Grabbed geojson schema from here: https://github.com/fge/sample-json-schemas/tree/master/geojson
        InputStream geoJsonSchemaInputStream = TypeInferrer.class.getResourceAsStream("/schemas/geojson/geojson.json");
        JSONObject rawGeoJsonSchema = new JSONObject(new JSONTokener(geoJsonSchemaInputStream));
        this.setGeoJsonSchema(SchemaLoader.load(rawGeoJsonSchema));
    }
    this.getGeoJsonSchema().validate(geoJson);
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:19,代码来源:TypeInferrer.java

示例4: validateTopoJsonSchema

import org.everit.json.schema.loader.SchemaLoader; //导入依赖的package包/类
/**
 * We only want to go through this initialization if we have to because it's a
 * performance issue the first time it is executed.
 * Because of this, so we don't include this logic in the constructor and only
 * call it when it is actually required after trying all other type inferral.
 * @param topoJson 
 */
private void validateTopoJsonSchema(JSONObject topoJson){
    if(this.getTopoJsonSchema() == null){
        // FIXME: Maybe this infering against topojson scheme is too much.
        // Grabbed topojson schema from here: https://github.com/nhuebel/TopoJSON_schema
        InputStream topoJsonSchemaInputStream = TypeInferrer.class.getResourceAsStream("/schemas/geojson/topojson.json");
        JSONObject rawTopoJsonSchema = new JSONObject(new JSONTokener(topoJsonSchemaInputStream));
        this.setTopoJsonSchema(SchemaLoader.load(rawTopoJsonSchema));
    }
    this.getTopoJsonSchema().validate(topoJson);
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:18,代码来源:TypeInferrer.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: JSONSchemaValidator

import org.everit.json.schema.loader.SchemaLoader; //导入依赖的package包/类
JSONSchemaValidator(final JSONObject effectiveSchema) {
    schema = SchemaLoader
            .builder()
            .schemaJson(effectiveSchema)
            .addFormatValidator("date-time", DATE_TIME_VALIDATOR)
            .build()
            .load()
            .build();
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:10,代码来源:EventBodyMustRespectSchema.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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