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