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


Java JsonLoader.fromString方法代码示例

本文整理汇总了Java中com.github.fge.jackson.JsonLoader.fromString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonLoader.fromString方法的具体用法?Java JsonLoader.fromString怎么用?Java JsonLoader.fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.fge.jackson.JsonLoader的用法示例。


在下文中一共展示了JsonLoader.fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.github.fge.jackson.JsonLoader; //导入方法依赖的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: isValid

import com.github.fge.jackson.JsonLoader; //导入方法依赖的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

示例3: validate

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public ValidationErrors validate(String schema, String requestBody) {
    ValidationErrors errors = new ValidationErrors();

    try {
        JsonNode schemaNode = JsonLoader.fromString(schema);
        JsonNode dataNode = JsonLoader.fromString(requestBody);

        ProcessingReport report = JsonSchemaFactory.byDefault().getJsonSchema(schemaNode).validate(dataNode);

        if (!report.isSuccess())
            report.iterator().forEachRemaining(m -> errors.addMessage("[ %s ] [ body ] %s", bodyType, m.getMessage()));
    } catch (Exception e) {
        errors.addMessage("[ %s ] [ body ] Unexpected error of [ %s ] while validating JSON content", bodyType, e.getMessage());
    }
    return errors;
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:17,代码来源:JsonContentValidator.java

示例4: assertMatchesJsonSchema

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
private void assertMatchesJsonSchema(final String json) {
    try {
        final ObjectNode rootNode = (ObjectNode) JsonLoader.fromString(json);
        final ObjectNode contextNode = (ObjectNode) rootNode.get("context");
        if (contextNode != null) {
            contextNode.remove("logger");
            contextNode.remove("MDC_KEY");
            contextNode.remove("CONTEXT_KEY1");
            contextNode.remove("CONTEXT_KEY2");
            contextNode.remove("CONTEXT_KEY3");
            contextNode.remove("CONTEXT_KEY4");
            contextNode.remove("CONTEXT_KEY5");
            contextNode.remove("CONTEXT_KEY6");
        }
        final ProcessingReport report = _validator.validate(STENO_SCHEMA, rootNode);
        Assert.assertTrue(report.toString(), report.isSuccess());
    } catch (final IOException | ProcessingException e) {
        Assert.fail("Failed with exception: " + e);
    }
}
 
开发者ID:ArpNetworking,项目名称:logback-steno,代码行数:21,代码来源:StenoEncoderTest.java

示例5: validateJson

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
protected void validateJson(String jsonFileName) throws IOException, ProcessingException, JsonLdError {

        JsonNode schema = getSchema();
        assertNotNull(schema);

        String jsonStr = getJson(jsonFileName);
        assertNotNull(jsonStr);

        Object jsonObj = JsonUtils.fromString(jsonStr);
        List<Object> expandedJson = JsonLdProcessor.expand(jsonObj);
        jsonStr = JsonUtils.toString(expandedJson);
        JsonNode json = JsonLoader.fromString(jsonStr);

        JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator();
        ProcessingReport processingReport = jsonValidator.validate(schema, json);
        assertNotNull(processingReport);
        if (!processingReport.isSuccess()) {

            ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
            assertNotNull(jsonArray);

            Iterator<ProcessingMessage> iterator = processingReport.iterator();
            while (iterator.hasNext()) {
                ProcessingMessage processingMessage = iterator.next();
                jsonArray.add(processingMessage.asJson());
            }

            String errorJson = JsonUtils.toPrettyString(jsonArray);
            assertNotNull(errorJson);

            fail(errorJson);
        }
    }
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:34,代码来源:AbstractSchemaValidatorTest.java

示例6: validateJSON

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
/**
 * Uses {@link JsonSchema} to validate JSON against A JSON Schema File
 *
 * @param jsonSchema the schema
 * @param json       the json to be validated.
 * @return true if the json matches the json schema
 * @see <a href="https://github.com/fge/json-schema-validator">JSON Schema Validator</a>
 */
public static boolean validateJSON(@NotNull String jsonSchema, @NotNull String json) {
    try {
        JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(JsonLoader.fromString(jsonSchema));
        JsonNode jsonToBeValidated = JsonLoader.fromString(json);
        return schema.validInstance(jsonToBeValidated);
    } catch (IOException | ProcessingException ignored) {
    }
    return false;
}
 
开发者ID:CognitiveJ,项目名称:wssimulator,代码行数:18,代码来源:WSSimulatorValidation.java

示例7: setup

import com.github.fge.jackson.JsonLoader; //导入方法依赖的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

示例8: validate

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public void validate(String ConfigurationFile) throws IOException, ProcessingException, IllegalSchemaException {
    JsonNode Configuration = JsonLoader.fromString(ConfigurationFile);

    ProcessingReport r1 = VALIDATOR.validate(
            ConfigurationSchema,
            Configuration
    );

    if (!r1.isSuccess()) {
        Iterator<ProcessingMessage> it = r1.iterator();
        ProcessingMessage pm = it.next();
        JSONObject o = new JSONObject(pm.asJson().toString());
        throw new IllegalSchemaException(o.toString(4));
    }
}
 
开发者ID:MKLab-ITI,项目名称:easIE,代码行数:16,代码来源:ConfigurationValidator.java

示例9: validateJsonData

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
protected boolean validateJsonData(final String jsonSchema, final String jsonData) throws Exception {
	final JsonNode d = JsonLoader.fromString(jsonData);
	final JsonNode s = JsonLoader.fromString(jsonSchema);

	final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
	JsonValidator v = factory.getValidator();

	ProcessingReport report = v.validate(s, d);

	return report.toString().contains("success");
}
 
开发者ID:apache,项目名称:metron,代码行数:12,代码来源:CEFParserTest.java

示例10: create

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public JsonSchema create(String schemaString) {
	JsonSchema jsonSchema = null;
	try {
		JsonNode schemaNode = JsonLoader.fromString(schemaString);
		if (!getJsonSchemaFactory().getSyntaxValidator().schemaIsValid(schemaNode)) {
			throw new InvalidSchemaException("JSON Schema is invalid" + getDescriptionAppendable());
		}
		jsonSchema = getJsonSchemaFactory().getJsonSchema(schemaNode);
	}
	catch (NullPointerException | IOException | ProcessingException ex) {
		throw new InvalidSchemaException("JSON Schema could not be loaded" + getDescriptionAppendable(), ex);
	}
	return jsonSchema;
}
 
开发者ID:galan,项目名称:verjson,代码行数:15,代码来源:Validation.java

示例11: validate

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
@Override
public final ValidationResult validate(String json) throws IOException {
	JsonNode jsonNode = JsonLoader.fromString(json);
	return getValidationResult(jsonNode);
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:6,代码来源:GenericOpenRtbValidator.java

示例12: getJsonNode

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
public static JsonNode getJsonNode(String jsonText) 
throws IOException
{
    return JsonLoader.fromString(jsonText);
}
 
开发者ID:deib-polimi,项目名称:diceH2020-space4clouds_shared,代码行数:6,代码来源:ValidationUtils.java

示例13: validate

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
protected String validate(String jsonStr, JsonNode validationSchema) throws ProcessingException, IOException {

        JsonNode json = JsonLoader.fromString(jsonStr);

        JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator();
        ProcessingReport processingReport = jsonValidator.validate(validationSchema, json);
        if (!processingReport.isSuccess()) {

            ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();

            for (ProcessingMessage processingMessage : processingReport) {
                jsonArray.add(processingMessage.asJson());
            }

            return JsonUtils.toPrettyString(jsonArray);
        }

        return null;
    }
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:20,代码来源:AbstractMessageConverter.java

示例14: getSchema

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
private JsonNode getSchema() throws IOException {
    String jsonStr = getJson(getSchemaFileName());
    return JsonLoader.fromString(jsonStr);
}
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:5,代码来源:AbstractSchemaValidatorTest.java

示例15: processTuple

import com.github.fge.jackson.JsonLoader; //导入方法依赖的package包/类
@Override
public void processTuple(byte[] tuple)
{
  if (tuple == null) {
    if (err.isConnected()) {
      err.emit(new KeyValPair<String, String>(null, "null tuple"));
    }
    errorTupleCount++;
    return;
  }
  String incomingString = new String(tuple);
  try {
    if (schema != null) {
      ProcessingReport report = null;
      JsonNode data = JsonLoader.fromString(incomingString);
      report = schema.validate(data);
      if (report != null && !report.isSuccess()) {
        Iterator<ProcessingMessage> iter = report.iterator();
        StringBuilder s = new StringBuilder();
        while (iter.hasNext()) {
          ProcessingMessage pm = iter.next();
          s.append(pm.asJson().get("instance").findValue("pointer")).append(":").append(pm.asJson().get("message"))
              .append(",");
        }
        s.setLength(s.length() - 1);
        errorTupleCount++;
        if (err.isConnected()) {
          err.emit(new KeyValPair<String, String>(incomingString, s.toString()));
        }
        return;
      }
    }
    if (parsedOutput.isConnected()) {
      parsedOutput.emit(new JSONObject(incomingString));
      parsedOutputCount++;
    }
    if (out.isConnected()) {
      out.emit(objMapper.readValue(tuple, clazz));
      emittedObjectCount++;
    }
  } catch (JSONException | ProcessingException | IOException e) {
    errorTupleCount++;
    if (err.isConnected()) {
      err.emit(new KeyValPair<String, String>(incomingString, e.getMessage()));
    }
    logger.error("Failed to parse json tuple {}, Exception = {} ", tuple, e);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:49,代码来源:JsonParser.java


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