本文整理汇总了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");
}
示例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));
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
}
示例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);
}
示例11: whenSchemaGenerated
import org.everit.json.schema.loader.SchemaLoader; //导入方法依赖的package包/类
private void whenSchemaGenerated() {
schemaString = generator.generateSchema(fieldDescriptors);
schema = SchemaLoader.load(new JSONObject(schemaString));
}
示例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);
}
示例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);
}
示例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;
}