Example usage for com.fasterxml.jackson.databind JsonNode textValue

List of usage examples for com.fasterxml.jackson.databind JsonNode textValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode textValue.

Prototype

public String textValue() 

Source Link

Usage

From source file:com.strategicgains.hyperexpress.serialization.siren.jackson.SirenResourceDeserializer.java

/**
 * @param resource//  w ww.j  a  va 2  s  .  c o  m
 * @param field
 */
private void addAllLinks(SirenResource resource, Entry<String, JsonNode> field) {
    LinkBuilder lb = new LinkBuilder();
    lb.rel(field.getKey());
    Iterator<JsonNode> values = field.getValue().elements();

    while (values.hasNext()) {
        JsonNode value = values.next();
        Iterator<JsonNode> elements = value.elements();

        while (elements.hasNext()) {
            JsonNode element = elements.next();
            lb.set(element.asText(), element.textValue());
        }

        resource.addLink(lb.build());
        lb.clearAttributes();
    }
}

From source file:com.rusticisoftware.tincan.Attachment.java

public Attachment(JsonNode jsonNode) throws URISyntaxException, MalformedURLException {
    JsonNode usageTypeNode = jsonNode.path("usageType");
    if (!usageTypeNode.isMissingNode()) {
        this.setUsageType(new URI(usageTypeNode.textValue()));
    }//from   w  w w.ja  va  2s  . c om

    JsonNode displayNode = jsonNode.path("display");
    if (!displayNode.isMissingNode()) {
        this.setDisplay(new LanguageMap(displayNode));
    }

    JsonNode descriptionNode = jsonNode.path("description");
    if (!descriptionNode.isMissingNode()) {
        this.setDescription(new LanguageMap(descriptionNode));
    }

    JsonNode contentTypeNode = jsonNode.path("contentType");
    if (!contentTypeNode.isMissingNode()) {
        this.setContentType(contentTypeNode.textValue());
    }

    JsonNode lengthNode = jsonNode.path("length");
    if (!lengthNode.isMissingNode()) {
        this.setLength(lengthNode.intValue());
    }

    JsonNode sha2Node = jsonNode.path("sha2");
    if (!sha2Node.isMissingNode()) {
        this.setSha2(sha2Node.textValue());
    }

    JsonNode fileUrlNode = jsonNode.path("fileUrl");
    if (!fileUrlNode.isMissingNode()) {
        this.setFileUrl(new URL(fileUrlNode.textValue()));
    }
}

From source file:com.rusticisoftware.tincan.Result.java

public Result(JsonNode jsonNode) throws URISyntaxException {
    this();/*from   w  ww.  j  a v  a2 s.  c o  m*/

    JsonNode scoreNode = jsonNode.path("score");
    if (!scoreNode.isMissingNode()) {
        this.setScore(new Score(scoreNode));
    }

    JsonNode successNode = jsonNode.path("success");
    if (!successNode.isMissingNode()) {
        this.setSuccess(successNode.booleanValue());
    }

    JsonNode completionNode = jsonNode.path("completion");
    if (!completionNode.isMissingNode()) {
        this.setCompletion(completionNode.booleanValue());
    }

    JsonNode durationNode = jsonNode.path("duration");
    if (!durationNode.isMissingNode()) {
        this.setDuration(new Period(durationNode.textValue()));
    }

    JsonNode responseNode = jsonNode.path("response");
    if (!responseNode.isMissingNode()) {
        this.setResponse(responseNode.textValue());
    }

    JsonNode extensionsNode = jsonNode.path("extensions");
    if (!extensionsNode.isMissingNode()) {
        this.setExtensions(new Extensions(extensionsNode));
    }
}

From source file:com.strategicgains.hyperexpress.serialization.jackson.HalResourceDeserializer.java

/**
 * @param resource//from   w w  w . jav a  2s  .c  o  m
 * @param field
 */
private void addAllLinks(HalResource resource, Entry<String, JsonNode> field) {
    LinkBuilder lb = new LinkBuilder();
    lb.rel(field.getKey());
    Iterator<JsonNode> values = field.getValue().elements();

    while (values.hasNext()) {
        JsonNode value = values.next();
        Iterator<JsonNode> elements = value.elements();

        while (elements.hasNext()) {
            JsonNode element = elements.next();
            lb.set(element.asText(), element.textValue());
        }

        resource.addLink(lb.build());
        lb.clearAttributes();
    }
}

From source file:com.vaporwarecorp.mirror.feature.AbstractCommand.java

@Override
public boolean matches(CommandResult commandResult) {
    if (!getCommandKind().equals(commandResult.getCommandKind())) {
        return false;
    }/*  ww  w .  j  ava  2s . c o  m*/

    JsonNode key = commandResult.getJsonNode().get(getCommandTypeKey());
    if (key != null) {
        return getCommandTypeValue().equals(key.textValue());
    }
    key = commandResult.getNativeData();
    if (key != null) {
        key = key.findValue(getCommandTypeKey());
        if (key != null) {
            return getCommandTypeValue().equals(key.textValue());
        }
    }
    return false;
}

From source file:eu.eubrazilcc.lvl.oauth2.rest.jackson.LinkedInMapper.java

public String readValue(final String name) {
    checkArgument(isNotBlank(name), "Uninitialized or invalid name");
    final JsonNode node = rootNode.path(name);
    checkState(!node.isMissingNode(), "Could not find: " + name);
    final String value = trimToNull(node.textValue());
    checkState(isNotBlank(value), "Empty string is not a valid value");
    return value;
}

From source file:com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.java

private int diffSize(ArrayNode diff) {
    int acc = 0;/*from   w w w .j a v a2 s.c om*/
    for (JsonNode child : diff) {
        String operation = child.findValue("op").textValue();
        JsonNode pathString = getFromPathString(operation, child);
        List<String> path = getPath(pathString.textValue());
        if (!arrayOrderIgnoredAndIsArrayMove(operation, path)
                && !extraElementsIgnoredAndIsAddition(operation)) {
            JsonNode valueNode = child.findValue("value");
            JsonNode referencedExpectedNode = getNodeAtPath(expected, pathString);
            if (valueNode == null) {
                acc += deepSize(referencedExpectedNode);
            } else {
                acc += maxDeepSize(referencedExpectedNode, valueNode);
            }
        }
    }

    return acc;
}

From source file:org.activiti.rest.service.api.legacy.process.StartProcessInstanceResource.java

@Post
public StartProcessInstanceResponse startProcessInstance(Representation entity) {
    try {/*from w ww.j  a  va 2s  .c  o m*/
        if (authenticate() == false)
            return null;

        String startParams = entity.getText();
        JsonNode startJSON = new ObjectMapper().readTree(startParams);
        String processDefinitionKey = startJSON.path("processDefinitionKey").textValue();
        String processDefinitionId = null;
        if (processDefinitionKey == null) {
            processDefinitionId = startJSON.path("processDefinitionId").textValue();
        }
        JsonNode businessKeyJson = startJSON.path("businessKey");
        String businessKey = null;
        if (businessKeyJson != null) {
            businessKey = businessKeyJson.textValue();
        }

        Map<String, Object> variables = retrieveVariables(startJSON);
        variables.remove("processDefinitionId");
        variables.remove("processDefinitionKey");
        variables.remove("businessKey");

        ProcessInstance processInstance = null;
        if (processDefinitionKey != null) {
            processInstance = ActivitiUtil.getRuntimeService().startProcessInstanceByKey(processDefinitionKey,
                    businessKey, variables);
        } else {
            processInstance = ActivitiUtil.getRuntimeService().startProcessInstanceById(processDefinitionId,
                    businessKey, variables);
        }
        StartProcessInstanceResponse response = new StartProcessInstanceResponse(processInstance);
        return response;

    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        }
        throw new ActivitiException("Failed to retrieve the process definition parameters", e);
    }

}

From source file:net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker.java

public VisitReport visit(BeanshellActivity activity, List<Object> ancestors) {
    Object subject = (Processor) VisitReport.findAncestor(ancestors, Processor.class);
    if (subject == null) {
        // Fall back to using the activity itself as the subject of the reports
        subject = activity;//  w w w  . j a  v a2s.c  o m
    }
    List<VisitReport> reports = new ArrayList<VisitReport>();

    String script = activity.getConfiguration().get("script").textValue();
    if (!script.trim().endsWith(";")) {
        /** Missing ; on last line is not allowed by Parser,
         * but is allowed by Interpreter.eval() used at runtime
         */
        script = script + ";";
    }
    Parser parser = new Parser(new StringReader(script));
    try {
        while (!parser.Line())
            ;
        reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Script OK", HealthCheck.NO_PROBLEM,
                Status.OK));
    } catch (ParseException e) {
        VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, e.getMessage(),
                HealthCheck.INVALID_SCRIPT, Status.SEVERE);
        report.setProperty("exception", e);
        reports.add(report);
    }

    // Check if we can find all the Beanshell's dependencies
    if (activity.getConfiguration().has("localDependency")) {
        LinkedHashSet<String> localDependencies = new LinkedHashSet<>();
        for (JsonNode localDependency : activity.getConfiguration().get("localDependency")) {
            localDependencies.add(localDependency.textValue());
        }

        String[] jarArray = activity.libDir.list(new FileExtFilter(".jar"));
        if (jarArray != null) {
            List<String> jarFiles = Arrays.asList(jarArray); // URLs of all jars found in the lib directory
            for (String jar : localDependencies) {
                if (jarFiles.contains(jar)) {
                    localDependencies.remove(jar);
                }
            }
        }
        if (localDependencies.isEmpty()) { // all dependencies found
            reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies found",
                    HealthCheck.NO_PROBLEM, Status.OK));
        } else {
            VisitReport vr = new VisitReport(HealthCheck.getInstance(), subject,
                    "Beanshell dependencies missing", HealthCheck.MISSING_DEPENDENCY, Status.SEVERE);
            vr.setProperty("dependencies", localDependencies);
            vr.setProperty("directory", activity.libDir);
            reports.add(vr);
        }

    }
    Status status = VisitReport.getWorstStatus(reports);
    VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell report",
            HealthCheck.NO_PROBLEM, status, reports);

    return report;

}

From source file:com.github.fge.jsonschema.processors.format.FormatProcessor.java

@Override
public ValidatorList process(final ProcessingReport report, final ValidatorList input)
        throws ProcessingException {
    final SchemaContext context = input.getContext();
    final JsonNode node = context.getSchema().getNode().get("format");

    if (node == null)
        return input;

    final String fmt = node.textValue();
    final FormatAttribute attr = attributes.get(fmt);

    if (attr == null) {
        report.warn(input.newMessage().put("domain", "validation").put("keyword", "format")
                .setMessage(bundle.getMessage("warn.format.notSupported")).putArgument("attribute", fmt));
        return input;
    }//from w ww .j  a v  a2 s .  c  o  m

    final NodeType type = context.getInstanceType();

    if (!attr.supportedTypes().contains(type))
        return input;

    final List<KeywordValidator> validators = Lists.newArrayList(input);
    validators.add(formatValidator(attr));

    return new ValidatorList(context, validators);
}