當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonSchemaFactory.getJsonSchema方法代碼示例

本文整理匯總了Java中com.github.fge.jsonschema.main.JsonSchemaFactory.getJsonSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonSchemaFactory.getJsonSchema方法的具體用法?Java JsonSchemaFactory.getJsonSchema怎麽用?Java JsonSchemaFactory.getJsonSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.fge.jsonschema.main.JsonSchemaFactory的用法示例。


在下文中一共展示了JsonSchemaFactory.getJsonSchema方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validate

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
@SneakyThrows
private boolean validate(Map<String, Object> data, String jsonSchema) {

    String stringData = objectMapper.writeValueAsString(data);
    log.debug("Validation data. map: {}, jsonData: {}", data, stringData);

    JsonNode schemaNode = JsonLoader.fromString(jsonSchema);

    JsonNode dataNode = JsonLoader.fromString(stringData);
    JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    JsonSchema schema = factory.getJsonSchema(schemaNode);
    val report = schema.validate(dataNode);

    boolean isSuccess = report.isSuccess();
    if (!isSuccess) {
        log.info("Validation data report: {}", report.toString().replaceAll("\n", " | "));
    }
    return isSuccess;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:20,代碼來源:JsonDataValidator.java

示例2: checkSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
private void checkSchema(File output)
{
    try
    {
        JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        URL schemaPath = getClass().getResource("/swagger-schema.json");
        JsonSchema schema = factory.getJsonSchema(schemaPath.toString());
        JsonNode json = JsonLoader.fromFile(output);

        ProcessingReport report = schema.validate(json);
        System.out.println(report);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:mauriciotogneri,項目名稱:stewie,代碼行數:18,代碼來源:Stewie.java

示例3: isValid

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
public static boolean isValid(String json, String schema) throws Exception {
    JsonNode schemaNode = JsonLoader.fromString(schema);       
    JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    JsonSchema jsonSchema = factory.getJsonSchema(schemaNode); 
    JsonNode jsonNode = JsonLoader.fromString(json);
    ProcessingReport report = jsonSchema.validate(jsonNode);
    logger.debug("report: {}", report);
    return report.isSuccess();
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:10,代碼來源:SchemaUtils.java

示例4: isValid

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
public boolean isValid(JsonNode jsonNode) {
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    log.verboseOutput("Checking against schema. Available at 'https://raw.githubusercontent.com/pivio/pivio-client/master/src/main/resources/pivio-schema.json'.", configuration.isVerbose());
    try {
        String schemaContent = readFromJARFile("/pivio-schema.json");
        JsonNode schemaNode = new ObjectMapper().readTree(schemaContent);
        final JsonSchema jsonSchema = factory.getJsonSchema(schemaNode);
        ProcessingReport processingReport = jsonSchema.validate(jsonNode);
        for (ProcessingMessage processingMessage : processingReport) {
            String pointer = processingMessage.asJson().get("instance").get("pointer").asText();
            log.output(pointer + " : " + processingMessage.getMessage());
        }
        return processingReport.isSuccess();
    } catch (ProcessingException | IOException e ) {
        log.output("Error processing Json. "+e.getMessage());
        return false;
    }
}
 
開發者ID:pivio,項目名稱:pivio-client,代碼行數:19,代碼來源:SchemaValidator.java

示例5: _validate

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
protected ProcessingReport _validate(JsonNode json) throws IOException {
    final JsonNode belSchema = JsonLoader.fromResource("/bel-json-graph.schema.json");
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    final JsonSchema schema;
    try {
        schema = factory.getJsonSchema(belSchema);
        return schema.validate(json, true);
    } catch (ProcessingException e) {
        throw new IOException(e);
    }
}
 
開發者ID:jsongraph,項目名稱:jgf-app,代碼行數:12,代碼來源:GraphReaderImpl.java

示例6: validateSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
private JsonSchema validateSchema(JsonNode jsonSchema)
        throws UnRAVLException {

    try {
        final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        final JsonSchema schema = factory.getJsonSchema(jsonSchema);
        SyntaxValidator syntaxValidator = factory.getSyntaxValidator();
        if (!syntaxValidator.schemaIsValid(jsonSchema)) {
            throw new UnRAVLException("JSON schema is invalid");
        }
        ProcessingReport report = syntaxValidator
                .validateSchema(jsonSchema);
        boolean success = report.isSuccess();
        if (!success) {
            throw new UnRAVLAssertionException(report.toString());
        }
        return schema;
    } catch (ProcessingException e) {
        throw new UnRAVLException(e);
    }
}
 
開發者ID:sassoftware,項目名稱:unravl,代碼行數:22,代碼來源:SchemaAssertion.java

示例7: loadSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
/**
 * Load a schema from given resourceName.
 *
 * @param resourceName
 * @return the schema
 * @throws ProcessingException
 * @throws IOException
 */
public static JsonSchema loadSchema(String resourceName) throws ProcessingException, IOException {
    JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    SyntaxValidator validator = factory.getSyntaxValidator();

    JsonNode node = loadJsonNode(resourceName);

    ProcessingReport report = validator.validateSchema(node);
    if (!report.isSuccess()) {
        throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
    }

    JsonSchema schema = factory.getJsonSchema("resource:/" + resourceName);
    if (null == schema) {
        throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
    }

    return schema;
}
 
開發者ID:lightblue-platform,項目名稱:lightblue-core,代碼行數:27,代碼來源:JsonUtils.java

示例8: getSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
@Override
public CJsonSchema getSchema(final IActivityLogger aLogger,
		final JSONObject aSchema) throws SchemaException {
	// create schema
	try {
		JsonSchemaFactory wFactory = JsonSchemaFactory.byDefault();
		aLogger.logDebug(this, "getSchema",
				"create JsonNode fro JSONObject for the schema");
		ObjectMapper wMapper = new ObjectMapper();
		JsonNode wSchema = wMapper.readTree(aSchema.toString());

		aLogger.logDebug(this, "getSchema", "create JsonSchema");
		return new CJsonSchema(wFactory.getJsonSchema(wSchema), aSchema);
	} catch (Exception e) {
		throw new SchemaException(e, e.getMessage());
	}
}
 
開發者ID:isandlaTech,項目名稱:cohorte-utilities,代碼行數:18,代碼來源:CJsonValidatorDefault.java

示例9: GenericOpenRtbValidator

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
/**
    * Constructs a JSON validator using the given schema read as a resource.
    * 
    * @param schemaResource
    *            the schema resource
    */
   GenericOpenRtbValidator(String schemaResource) {
	try {
		JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
		JsonNode jsonNode = JsonLoader.fromResource(schemaResource);
		schema = factory.getJsonSchema(jsonNode);
	} catch (IOException | ProcessingException e) {
		throw new IllegalStateException("could not initialize validator due to previous exception", e);
	}
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:16,代碼來源:GenericOpenRtbValidator.java

示例10: getSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
private JsonSchema getSchema() throws IOException, ProcessingException {
    String fileName = String.format("%s/conf/schemas/%s.json",
            env.rootPath().getAbsolutePath(), configuration.schema());
    JsonNode schemaNode = JsonLoader.fromFile(new File(fileName));
    JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    return factory.getJsonSchema(schemaNode);
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:8,代碼來源:JsonSchemaValidator.java

示例11: validate

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
public static boolean validate(String data, ObjectMapper objectMapper, BenderSchema benderSchema)
    throws ConfigurationException {
  ProcessingReport report;
  try {
    /*
     * Create object
     */
    JsonNode node = objectMapper.readTree(data);

    /*
     * Create JSON schema
     */
    JsonNode jsonSchema = benderSchema.getSchema();

    /*
     * Validate
     */
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    final JsonSchema schema = factory.getJsonSchema(jsonSchema);
    report = schema.validate(node);
  } catch (IOException | ProcessingException ioe) {
    throw new ConfigurationException("unable to validate config", ioe);
  }

  if (report.isSuccess()) {
    return true;
  } else {
    throw new ConfigurationException("invalid config file",
        report.iterator().next().asException());
  }
}
 
開發者ID:Nextdoor,項目名稱:bender,代碼行數:32,代碼來源:BenderConfig.java

示例12: _getSchemaNode

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
private static JsonSchema _getSchemaNode(JsonNode jsonNode)
throws ProcessingException
{
    final JsonNode schemaIdentifier = jsonNode.get(JSON_SCHEMA_IDENTIFIER_ELEMENT);
    if (null == schemaIdentifier){
        ((ObjectNode) jsonNode).put(JSON_SCHEMA_IDENTIFIER_ELEMENT, JSON_V4_SCHEMA_IDENTIFIER);
    }
    
    final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
    return factory.getJsonSchema(jsonNode);
}
 
開發者ID:deib-polimi,項目名稱:diceH2020-space4clouds_shared,代碼行數:12,代碼來源:ValidationUtils.java

示例13: validateSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
/**
 * Checks if the specified json fulfills the specified schema.
 *
 * @param schemaName        The name of the schema.
 * @param contentObjectTree The json which is analysed.
 * @return TRUE if the json fulfills the specified schema, FALSE otherwise.
 * @throws ResourceException if an error occurred.
 */
private boolean validateSchema(String schemaName, JsonNode contentObjectTree) throws ResourceException {
    try {
        URITranslatorConfiguration translatorCfg = URITranslatorConfiguration.newBuilder().setNamespace(NAMESPACE).freeze();
        LoadingConfiguration cfg = LoadingConfiguration.newBuilder().setURITranslatorConfiguration(translatorCfg).freeze();
        JsonSchemaFactory factory = JsonSchemaFactory.newBuilder().setLoadingConfiguration(cfg).freeze();
        JsonSchema schema = factory.getJsonSchema(schemaName);
        ProcessingReport report = schema.validate(contentObjectTree);
        return report.isSuccess();
    } catch (ProcessingException e) {
        throw new ResourceException(e);
    }
}
 
開發者ID:qaware,項目名稱:gradle-cloud-deployer,代碼行數:21,代碼來源:MarathonResourceFactory.java

示例14: setup

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
@Override
public void setup(OperatorContext context)
{
  try {
    if (jsonSchema != null) {
      JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
      JsonNode schemaNode = JsonLoader.fromString(jsonSchema);
      schema = factory.getJsonSchema(schemaNode);
    }
    objMapper = new ObjectMapper();
    objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  } catch (ProcessingException | IOException e) {
    DTThrowable.wrapIfChecked(e);
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:16,代碼來源:JsonParser.java

示例15: validateJsonDataWithSchema

import com.github.fge.jsonschema.main.JsonSchemaFactory; //導入方法依賴的package包/類
@Override
public boolean validateJsonDataWithSchema(JsonNode data, JsonNode schema) {
    try {
        JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        // load the schema and validate
        JsonSchema jsonSchema = factory.getJsonSchema(schema);
        return jsonSchema.validInstance(data);
    } catch (ProcessingException ex) {
        logger.error(ex);
    }
    return false;
}
 
開發者ID:martin-kanis,項目名稱:relax-dms,代碼行數:13,代碼來源:DocumentServiceImpl.java


注:本文中的com.github.fge.jsonschema.main.JsonSchemaFactory.getJsonSchema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。