• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Schema类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

import org.everit.json.schema.Schema; //导入依赖的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: schemaFromFileTest

import org.everit.json.schema.Schema; //导入依赖的package包/类
@Test
public void schemaFromFileTest() throws Exception {
	Schema jsonSchema = BaseUtil.schemaFromFile("sample/component-schema.json");
	Assert.assertNotNull(jsonSchema);

	String schemaStr = jsonSchema.toString();
	Schema copySchema = BaseUtil.schemaFromString(schemaStr);

	Assert.assertNotNull(copySchema);
	Assert.assertEquals(jsonSchema, copySchema);

	File jsonFile = new File("sample/test-component.json");
	Assert.assertNotNull(jsonFile);

	String jsonData = FileUtils.readFileToString(jsonFile, Charset.defaultCharset());
	Assert.assertTrue("JSON string length greater than zero", (0 < jsonData.length()));

	BaseUtil.validateData(jsonSchema, jsonData);
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:20,代码来源:BaseUtilTest.java


示例3: compareItemSchemaArray

import org.everit.json.schema.Schema; //导入依赖的package包/类
private static void compareItemSchemaArray(final ArraySchema original, final ArraySchema update,
                                           final Stack<String> jsonPath, final List<SchemaChange> changes) {
    final List<Schema> emptyList = ImmutableList.of();
    final List<Schema> originalSchemas = MoreObjects.firstNonNull(original.getItemSchemas(), emptyList);
    final List<Schema> updateSchemas = MoreObjects.firstNonNull(update.getItemSchemas(), emptyList);

    if (originalSchemas.size() != updateSchemas.size()) {
        SchemaDiff.addChange(NUMBER_OF_ITEMS_CHANGED, jsonPath, changes);
    } else {
        final Iterator<Schema> originalIterator = originalSchemas.iterator();
        final Iterator<Schema> updateIterator = updateSchemas.iterator();
        int index = 0;
        while (originalIterator.hasNext()) {
            jsonPath.push("items/" + index);
            SchemaDiff.recursiveCheck(originalIterator.next(), updateIterator.next(), jsonPath, changes);
            jsonPath.pop();
            index += 1;
        }
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:21,代码来源:ArraySchemaDiff.java


示例4: recursiveCheck

import org.everit.json.schema.Schema; //导入依赖的package包/类
static void recursiveCheck(final CombinedSchema combinedSchemaOriginal, final CombinedSchema combinedSchemaUpdate,
                                   final Stack<String> jsonPath,
                                   final List<SchemaChange> changes) {
    if(combinedSchemaOriginal.getSubschemas().size() != combinedSchemaUpdate.getSubschemas().size()) {
        SchemaDiff.addChange(SUB_SCHEMA_CHANGED, jsonPath, changes);
    } else {
        if (!combinedSchemaOriginal.getCriterion().equals(combinedSchemaUpdate.getCriterion())) {
            SchemaDiff.addChange(COMPOSITION_METHOD_CHANGED, jsonPath, changes);
        } else {
            final Iterator<Schema> originalIterator = combinedSchemaOriginal.getSubschemas().iterator();
            final Iterator<Schema> updateIterator = combinedSchemaUpdate.getSubschemas().iterator();
            int index = 0;
            while (originalIterator.hasNext()) {
                jsonPath.push(validationCriteria(combinedSchemaOriginal.getCriterion()) + "/" + index);
                SchemaDiff.recursiveCheck(originalIterator.next(), updateIterator.next(), jsonPath, changes);
                jsonPath.pop();
                index += 1;
            }
        }
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:22,代码来源:CombinedSchemaDiff.java


示例5: compareProperties

import org.everit.json.schema.Schema; //导入依赖的package包/类
private static void compareProperties(final ObjectSchema original, final ObjectSchema update,
                                      final Stack<String> jsonPath, final List<SchemaChange> changes) {
    jsonPath.push("properties");
    for (final Map.Entry<String, Schema> property : original.getPropertySchemas().entrySet()) {
        jsonPath.push(property.getKey());
        if (!update.getPropertySchemas().containsKey(property.getKey())) {
            SchemaDiff.addChange(PROPERTY_REMOVED, jsonPath, changes);
        } else {
            SchemaDiff.recursiveCheck(property.getValue(), update.getPropertySchemas().get(property.getKey()),
                    jsonPath, changes);
        }
        jsonPath.pop();
    }
    if (update.getPropertySchemas().size() > original.getPropertySchemas().size()) {
        SchemaDiff.addChange(PROPERTIES_ADDED, jsonPath, changes);
    }
    jsonPath.pop();
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:19,代码来源:ObjectSchemaDiff.java


示例6: checkJsonSchemaCompatibility

import org.everit.json.schema.Schema; //导入依赖的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


示例7: get

import org.everit.json.schema.Schema; //导入依赖的package包/类
public Schema get(
        String schemaStoreDb,
        BsonValue schemaId)
        throws JsonSchemaNotFoundException {
    if (Bootstrapper.getConfiguration().isSchemaCacheEnabled()) {
        Optional<Schema> _schema = schemaCache.get(
                schemaStoreDb
                + SEPARATOR
                + schemaId);

        if (_schema != null && _schema.isPresent()) {
            return _schema.get();
        } else {
            // load it
            Schema s = load(schemaStoreDb, schemaId);

            schemaCache.put(schemaStoreDb + SEPARATOR + schemaId, s);

            return s;
        }
    } else {
        return load(schemaStoreDb, schemaId);
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:25,代码来源:JsonSchemaCacheSingleton.java


示例8: testLoadAndValidateInvalid

import org.everit.json.schema.Schema; //导入依赖的package包/类
@Test
public void testLoadAndValidateInvalid() throws Exception
{
	String schemaJson = gson.toJson(of("title", "Hello World Job", "type", "object", "properties",
			of("p1", of("type", "integer"), "p2", of("type", "integer")), "required", singletonList("p2")));
	Schema schema = jsonValidator.loadSchema(schemaJson);
	try
	{
		jsonValidator.validate("{\"p1\":\"10\"}", schema);
	}
	catch (MolgenisValidationException expected)
	{
		assertEquals(expected.getViolations(),
				Sets.newHashSet(new ConstraintViolation("#/p1: expected type: Number, found: String"),
						new ConstraintViolation("#: required key [p2] not found")));
	}
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:18,代码来源:JsonValidatorTest.java


示例9: validate

import org.everit.json.schema.Schema; //导入依赖的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


示例10: schemaFromFile

import org.everit.json.schema.Schema; //导入依赖的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


示例11: schemaFromResource

import org.everit.json.schema.Schema; //导入依赖的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


示例12: deploy

import org.everit.json.schema.Schema; //导入依赖的package包/类
/**
 * Deploy a component with given JSON configuration
 *
 * @param deployConfig Json configuration corresponding to a component to be deployed
 * @param future       Future to provide the status of deployment
 * @see <a href="http://vertx.io/docs/apidocs/io/vertx/core/Future.html" target="_blank">Future</a>
 */
public void deploy(JsonObject deployConfig, Future<Boolean> future) {
	if (null == this.vertx) {
		String errMesg = "Not setup yet! Call 'setup' method first.";

		logger.error(errMesg);
		future.fail(new Exception(errMesg));

		return;
	}

	try {
		Schema jsonSchema = BaseUtil.schemaFromResource("/deploy-opts-schema.json");
		String jsonData = deployConfig.toString();

		BaseUtil.validateData(jsonSchema, jsonData);
	} catch (ValidationException vldEx) {
		logger.error("Issue with deployment configuration validation!", vldEx);

		vldEx
				.getCausingExceptions()
				.stream()
				.map(ValidationException::getMessage)
				.forEach((errMsg) -> {
					logger.error(errMsg);
				});

		future.fail(vldEx);

		return;
	} catch (IOException ioEx) {
		logger.error("Issue while loading schema configuration!", ioEx);
		future.fail(ioEx);

		return;
	}

	DeployComponent component = this.setupComponent(deployConfig);
	this.deployRecords.deploy(component.getIdentifier(), component.getDeployOpts(), future);
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:47,代码来源:VtxDeployer.java


示例13: schemaFromResourceTest

import org.everit.json.schema.Schema; //导入依赖的package包/类
@Test
public void schemaFromResourceTest() throws Exception {
	Schema jsonSchema = BaseUtil.schemaFromResource("/deployer-schema.json");
	Assert.assertNotNull(jsonSchema);

	File jsonFile = new File("sample/no-cluster.json");
	Assert.assertNotNull(jsonFile);

	String jsonData = FileUtils.readFileToString(jsonFile, Charset.defaultCharset());
	Assert.assertTrue("JSON string length greater than zero", (0 < jsonData.length()));

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


示例14: invalidSchemaTest

import org.everit.json.schema.Schema; //导入依赖的package包/类
@Test
public void invalidSchemaTest() throws Exception {
	thrown.expect(ValidationException.class);

	Schema jsonSchema = BaseUtil.schemaFromResource("/deployer-schema.json");
	Assert.assertNotNull(jsonSchema);

	File jsonFile = new File("sample/test-component.json");
	Assert.assertNotNull(jsonFile);

	String jsonData = FileUtils.readFileToString(jsonFile, Charset.defaultCharset());
	Assert.assertTrue("JSON string length greater than zero", (0 < jsonData.length()));

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


示例15: validate

import org.everit.json.schema.Schema; //导入依赖的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


示例16: SchemaEvolutionService

import org.everit.json.schema.Schema; //导入依赖的package包/类
public SchemaEvolutionService(final Schema metaSchema,
                              final List<SchemaEvolutionConstraint> schemaEvolutionConstraints,
                              final SchemaDiff schemaDiff,
                              final Map<SchemaChange.Type, Version.Level> compatibleChanges,
                              final Map<SchemaChange.Type, Version.Level> forwardChanges,
                              final Map<SchemaChange.Type, String> errorMessages) {
    this.metaSchema = metaSchema;
    this.schemaEvolutionConstraints = schemaEvolutionConstraints;
    this.schemaDiff = schemaDiff;
    this.forwardChanges = forwardChanges;
    this.compatibleChanges = compatibleChanges;
    this.errorMessages = errorMessages;
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:14,代码来源:SchemaEvolutionService.java


示例17: collectChanges

import org.everit.json.schema.Schema; //导入依赖的package包/类
public List<SchemaChange> collectChanges(final Schema original, final Schema update) {
    final List<SchemaChange> changes = new ArrayList<>();
    final Stack<String> jsonPath = new Stack<>();

    recursiveCheck(original, update, jsonPath, changes);

    return changes;
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:9,代码来源:SchemaDiff.java


示例18: validatePartitionKeys

import org.everit.json.schema.Schema; //导入依赖的package包/类
private void validatePartitionKeys(final Schema schema, final EventTypeBase eventType)
        throws InvalidEventTypeException, JSONException, SchemaException {
    final List<String> absentFields = eventType.getPartitionKeyFields().stream()
            .filter(field -> !schema.definesProperty(convertToJSONPointer(field)))
            .collect(Collectors.toList());
    if (!absentFields.isEmpty()) {
        throw new InvalidEventTypeException("partition_key_fields " + absentFields + " absent in schema");
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:10,代码来源:EventTypeService.java


示例19: setUp

import org.everit.json.schema.Schema; //导入依赖的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


示例20: load

import org.everit.json.schema.Schema; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RoutesDefinition类代码示例发布时间:2022-05-22
下一篇:
Java Transaction类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap