Java Code Examples for com.github.fge.jackson.JacksonUtils

The following examples show how to use com.github.fge.jackson.JacksonUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected JsonNode buildResult(final String input)
    throws IOException
{
    final ValueHolder<String> holder = ValueHolder.hold("source", input);
    final ProcessingReport report = new ListProcessingReport();
    final ProcessingResult<ValueHolder<SchemaTree>> result
        = ProcessingResult.uncheckedResult(PROCESSOR, report, holder);

    final ProcessingReport processingReport = result.getReport();

    final ObjectNode ret = FACTORY.objectNode();
    final boolean success = processingReport.isSuccess();
    ret.put(VALID, success);

    final JsonNode content = success
        ? result.getResult().getValue().getBaseNode()
        : buildReport(result.getReport());

    ret.put(RESULTS, JacksonUtils.prettyPrint(content));
    return ret;
}
 
Example 2
private static JsonNode buildResult(final String rawSchema,
    final String rawData)
    throws IOException
{
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
        rawSchema);
    final boolean invalidData = fillWithData(ret, INPUT2, INVALID_INPUT2,
        rawData);

    final JsonNode schemaNode = ret.remove(INPUT);
    final JsonNode data = ret.remove(INPUT2);

    if (invalidSchema || invalidData)
        return ret;

    final ProcessingReport report
        = VALIDATOR.validateUnchecked(schemaNode, data);

    final boolean success = report.isSuccess();
    ret.put(VALID, success);
    final JsonNode node = ((AsJson) report).asJson();
    ret.put(RESULTS, JacksonUtils.prettyPrint(node));
    return ret;
}
 
Example 3
@Override
protected JsonNode buildResult(final String input)
    throws IOException, ProcessingException
{
    final ObjectNode ret = FACTORY.objectNode();

    final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
        input);

    final JsonNode schemaNode = ret.remove(INPUT);

    if (invalidSchema)
        return ret;

    final ProcessingReport report = VALIDATOR.validateSchema(schemaNode);
    final boolean success = report.isSuccess();

    ret.put(VALID, success);
    ret.put(RESULTS, JacksonUtils.prettyPrint(buildReport(report)));
    return ret;
}
 
Example 4
Source Project: aerogear-unifiedpush-server   Source File: UserParams.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JsonNode transform(JsonNode patched) throws IOException {
    Iterator<Map.Entry<String, JsonNode>> nodeIterator = patched.get("message").fields();
    while (nodeIterator.hasNext()) {
        Map.Entry<String, JsonNode> entry = nodeIterator.next();

        if (!KNOWN_KEYS.contains(entry.getKey())) {
            String json = format(MOVE_OP, entry.getKey());
            try {
                patched = JsonPatch.fromJson(JacksonUtils.getReader().readTree(json)).apply(patched);
            } catch (JsonPatchException e) {
                throw new RuntimeException("move operation could not be applied", e);
            }
        }
    }

    return patched;
}
 
Example 5
Source Project: arctic-sea   Source File: ValidationMatchers.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean describeProcessingReport(ProcessingReport report, JsonNode item,
        Description mismatchDescription) throws JsonProcessingException {
    if (!report.isSuccess()) {
        ObjectNode objectNode = JacksonUtils.nodeFactory().objectNode();
        objectNode.set(JSONConstants.INSTANCE, item);
        ArrayNode errors = objectNode.putArray(JSONConstants.ERRORS);
        for (ProcessingMessage m : report) {
            errors.add(m.asJson());
        }
        mismatchDescription.appendText(JacksonUtils.prettyPrint(objectNode));
    }
    return report.isSuccess();
}
 
Example 6
private static JsonNode buildResult(final String rawPatch,
    final String rawData)
    throws IOException
{
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
        rawPatch);
    final boolean invalidData = fillWithData(ret, INPUT2, INVALID_INPUT2,
        rawData);

    final JsonNode patchNode = ret.remove(INPUT);
    final JsonNode data = ret.remove(INPUT2);

    if (invalidSchema || invalidData)
        return ret;

    final JsonPatchInput input = new JsonPatchInput(patchNode, data);

    final ProcessingReport report = new ListProcessingReport();
    final ProcessingResult<ValueHolder<JsonNode>> result
        = ProcessingResult.uncheckedResult(PROCESSOR, report, input);

    final boolean success = result.isSuccess();
    ret.put(VALID, success);
    final JsonNode node = result.isSuccess() ? result.getResult()
        .getValue() : buildReport(result.getReport());
    ret.put(RESULTS, JacksonUtils.prettyPrint(node));
    return ret;
}
 
Example 7
private static JsonNode buildReport(final ProcessingReport report)
{
    final ArrayNode ret = JacksonUtils.nodeFactory().arrayNode();
    for (final ProcessingMessage message: report)
        ret.add(message.asJson());
    return ret;
}
 
Example 8
@Override
protected JsonNode buildResult(final String input)
    throws IOException, ProcessingException
{
    final ObjectNode ret = FACTORY.objectNode();

    final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
        input);

    final JsonNode schemaNode = ret.remove(INPUT);

    if (invalidSchema)
        return ret;

    final JsonTree tree = new SimpleJsonTree(schemaNode);
    final ValueHolder<JsonTree> holder = ValueHolder.hold(tree);

    final ProcessingReport report = new ListProcessingReport();
    final ProcessingResult<ValueHolder<SchemaTree>> result
        = ProcessingResult.uncheckedResult(PROCESSOR, report, holder);
    final boolean success = result.isSuccess();

    final JsonNode content = success
        ? result.getResult().getValue().getBaseNode()
        : buildReport(result.getReport());

    ret.put(VALID, success);
    ret.put(RESULTS, JacksonUtils.prettyPrint(content));
    return ret;
}
 
Example 9
@Override
protected JsonNode buildResult(final String input)
    throws IOException, ProcessingException
{
    final ObjectNode ret = FACTORY.objectNode();

    final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
        input);

    final JsonNode schemaNode = ret.remove(INPUT);

    if (invalidSchema)
        return ret;

    final SchemaTree tree
        = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schemaNode);
    final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree);

    final ProcessingReport report = new ListProcessingReport();
    final ProcessingResult<ValueHolder<String>> result
        = ProcessingResult.uncheckedResult(PROCESSOR, report, holder);

    final boolean  success = result.isSuccess();
    ret.put(VALID, success);

    final String content = success
        ? result.getResult().getValue()
        : JacksonUtils.prettyPrint(buildReport(result.getReport()));

    ret.put(RESULTS, content);
    return ret;
}
 
Example 10
@Override
protected JsonNode loadSample()
{
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode sample = SAMPLE_DATA.get(index);
    final ObjectNode ret = FACTORY.objectNode();
    ret.put(ResponseFields.INPUT, JacksonUtils.prettyPrint(sample));
    return ret;
}
 
Example 11
@Override
protected JsonNode loadSample()
{
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode sample = SAMPLE_DATA.get(index);
    final ObjectNode ret = FACTORY.objectNode();
    final Map<String, JsonNode> map = JacksonUtils.asMap(sample);
    for (final Map.Entry<String, JsonNode> entry: map.entrySet())
        ret.put(entry.getKey(), JacksonUtils.prettyPrint(entry.getValue()));

    return ret;
}
 
Example 12
@Override
protected JsonNode loadSample()
{
    final ObjectNode ret = FACTORY.objectNode();
    ret.put(ResponseFields.INPUT, JacksonUtils.prettyPrint(SAMPLE_SCHEMA));
    return ret;
}
 
Example 13
@Override
protected JsonNode loadSample()
{
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode sample = SAMPLE_DATA.get(index);
    final ObjectNode ret = FACTORY.objectNode();
    final Map<String, JsonNode> map = JacksonUtils.asMap(sample);
    for (final Map.Entry<String, JsonNode> entry: map.entrySet())
        ret.put(entry.getKey(), JacksonUtils.prettyPrint(entry.getValue()));

    return ret;
}
 
Example 14
@Override
protected JsonNode loadSample()
{
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode sample = SAMPLE_DATA.get(index);
    final ObjectNode ret = FACTORY.objectNode();
    ret.put(ResponseFields.INPUT, JacksonUtils.prettyPrint(sample));
    return ret;
}