@BeforeClass
  public void setUp() throws IOException, JsonSchemaException {
    final JsonNode schemaList = JsonLoader.fromResource("/ref/jsonresolver-schemas.json");
    testData = JsonLoader.fromResource("/ref/jsonresolver-testdata.json");

    manager = mock(URIManager.class);
    registry = new SchemaRegistry(manager);

    final Map<String, JsonNode> map = CollectionUtils.toMap(schemaList.fields());

    URI uri;
    JsonNode schema;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
      uri = URI.create(entry.getKey());
      schema = entry.getValue();
      when(manager.getContent(uri)).thenReturn(schema);
    }

    resolver = new JsonResolver(registry);
  }
예제 #2
0
파일: JsonUtil.java 프로젝트: jani00/core
  /**
   * Validates object against a JSON schema.
   *
   * @param o object to validate.
   * @param schemaResource schema used for validation.
   * @return {@link Validator}
   */
  public static Validator validateJson(Object o, String schemaResource) {
    JsonNode json = objectToJson(o);

    JsonNode schema;
    try {
      schema = JsonLoader.fromResource(schemaResource);
      return validateJson(json, schema);
    } catch (IOException e) {
      log.info(String.format("JsonUtils.validateJson(): Unable to load schema json"));
      Validator res = new Validator();
      res.addError("jsonerror", "Unable to load schema");
      return res;
    }
  }