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.vaporwarecorp.mirror.feature.AbstractCommand.java

protected String text(JsonNode node, String key) {
    JsonNode keyNode = jsonNodeValue(node, key);
    if (keyNode != null) {
        keyNode = keyNode.get(0);// w w w  .  j a  v a 2s  .co  m
        if (keyNode != null) {
            return StringUtils.trimToNull(keyNode.textValue());
        }
    }
    return null;
}

From source file:com.digitalpebble.storm.crawler.filtering.URLFilters.java

@Override
public void configure(Map stormConf, JsonNode jsonNode) {
    // initialises the filters
    List<URLFilter> filterLists = new ArrayList<>();

    // get the filters part
    String name = getClass().getCanonicalName();
    jsonNode = jsonNode.get(name);//ww  w.  j av a 2s .  c o  m

    if (jsonNode == null) {
        LOG.info("No field {} in JSON config. Skipping", name);
        filters = new URLFilter[0];
        return;
    }

    // conf node contains a list of objects
    Iterator<JsonNode> filterIter = jsonNode.elements();
    while (filterIter.hasNext()) {
        JsonNode afilterNode = filterIter.next();
        String filterName = "<unnamed>";
        JsonNode nameNode = afilterNode.get("name");
        if (nameNode != null) {
            filterName = nameNode.textValue();
        }
        JsonNode classNode = afilterNode.get("class");
        if (classNode == null) {
            LOG.error("Filter {} doesn't specified a 'class' attribute", filterName);
            continue;
        }
        String className = classNode.textValue().trim();
        filterName += '[' + className + ']';

        // check that it is available and implements the interface URLFilter
        try {
            Class<?> filterClass = Class.forName(className);
            boolean interfaceOK = URLFilter.class.isAssignableFrom(filterClass);
            if (!interfaceOK) {
                LOG.error("Class {} does not implement URLFilter", className);
                continue;
            }
            URLFilter filterInstance = (URLFilter) filterClass.newInstance();

            JsonNode paramNode = afilterNode.get("params");
            if (paramNode != null) {
                filterInstance.configure(stormConf, paramNode);
            } else {
                filterInstance.configure(stormConf, NullNode.getInstance());
            }

            filterLists.add(filterInstance);
            LOG.info("Loaded instance of class {}", className);
        } catch (Exception e) {
            LOG.error("Can't setup {}: {}", filterName, e);
            continue;
        }
    }

    filters = filterLists.toArray(new URLFilter[filterLists.size()]);
}

From source file:org.pac4j.oauth.profile.JsonList.java

/**
 * Add a single node to the JsonList.//from  w  ww . j  a va2  s. co m
 * 
 * @param node JSON node
 */
private void buildSingleNode(final JsonNode node) {
    if (this.clazz == String.class) {
        this.list.add((T) node.textValue());
    } else if (JsonObject.class.isAssignableFrom(this.clazz)) {
        try {
            final Constructor<T> constructor = this.clazz.getDeclaredConstructor();
            final T object = constructor.newInstance();
            ((JsonObject) object).buildFrom(node);
            this.list.add(object);
        } catch (final Exception e) {
            logger.error("Cannot build object", e);
        }
    }
}

From source file:org.obiba.mica.core.upgrade.Mica220Upgrade.java

private boolean propertyExistsInSchema(JsonNode schema) {

    Iterator<JsonNode> values = schema.get("properties").get("access").get("items").get("enum").elements();

    while (values.hasNext()) {
        JsonNode value = values.next();
        if (value.textValue().equals("biosamples"))
            return true;
    }/*w w  w.  j a  v  a 2  s.com*/

    return false;
}

From source file:com.amazonaws.service.apigateway.importer.impl.SchemaTransformer.java

private void buildSchemaReferenceMap(JsonNode model, JsonNode models, Map<String, String> modelMap) {
    Map<JsonNode, JsonNode> refs = new HashMap<>();
    findReferences(model, refs);//from ww  w . jav a2 s .  co m
    for (JsonNode ref : refs.keySet()) {
        String canonicalRef = ref.textValue();

        String schemaName = getSchemaName(canonicalRef);

        JsonNode subSchema = getSchema(schemaName, models);

        // replace reference values with inline definitions
        replaceRef((ObjectNode) refs.get(ref), schemaName);

        buildSchemaReferenceMap(subSchema, models, modelMap);

        modelMap.put(schemaName, serializeExisting(subSchema));
    }
}

From source file:com.amazonaws.service.apigateway.importer.impl.SchemaTransformer.java

private void buildSchemaReferenceMap(JsonNode model, JsonNode models, Map<String, String> modelMap,
        List<String> modelNames) {
    Map<JsonNode, JsonNode> refs = new HashMap<>();
    findReferences(model, refs);/*from w w w  .j  a  va 2 s  .c  o m*/

    for (JsonNode ref : refs.keySet()) {
        String canonicalRef = ref.textValue();
        String schemaName = getSchemaName(canonicalRef);
        JsonNode subSchema = getSchema(schemaName, models);
        // replace reference values with inline definitions
        replaceRef((ObjectNode) refs.get(ref), schemaName);
        if (!modelNames.contains(schemaName)) {
            modelNames.add(schemaName);
            buildSchemaReferenceMap(subSchema, models, modelMap, modelNames);
        }
        modelMap.put(schemaName, serializeExisting(subSchema));
    }
}

From source file:com.amazonaws.services.dynamodbv2.replication.manager.models.ReplicationGroupCoordinator.java

public ReplicationGroupStatus getStatus() {
    Client client = ClientBuilder.newClient();

    client.property(ClientProperties.CONNECT_TIMEOUT, 1000);
    client.property(ClientProperties.READ_TIMEOUT, 1000);

    WebTarget target = client.target(endpoint).path(DESCRIBE_REPLICATION_COORDINATOR_API);
    try {/*w  w  w. java 2 s  .  co  m*/
        JsonNode json = target.request().get(JsonNode.class);
        logger.fine("Received " + json);
        JsonNode statusField = json.get(REPLICATION_COORDINATOR_STATUS_FIELD);
        if (statusField != null) {
            return ReplicationGroupStatus.valueOf(statusField.textValue());
        } else {
            return ReplicationGroupStatus.UNKNOWN;
        }
    } catch (ProcessingException pe) {
        if (this.status == ReplicationGroupStatus.BOOTSTRAPPING) {
            return ReplicationGroupStatus.BOOTSTRAPPING;
        } else {
            return ReplicationGroupStatus.COORDINATOR_UNREACHABLE;
        }
    }
}

From source file:com.reprezen.swaggerparser.test.BigParseTest.java

private Object getValue(JsonNode node) {
    if (node.isNumber()) {
        return node.numberValue();
    } else if (node.isTextual()) {
        return node.textValue();
    } else if (node.isBoolean()) {
        return node.booleanValue();
    } else if (node.isNull()) {
        return null;
    } else {/*from ww w.j  ava  2 s. c  o m*/
        throw new IllegalArgumentException("Non-value JSON node got through value node filter");
    }
}

From source file:com.github.fge.jsonschema.syntax.checkers.SyntaxCheckersTest.java

@Test(dependsOnMethods = "keywordIsSupportedInThisDictionary", dataProvider = "getPointerTests")
public final void pointerDelegationWorksCorrectly(final JsonNode schema, final ArrayNode expectedPointers)
        throws ProcessingException, JsonPointerException {
    final SchemaTree tree = new CanonicalSchemaTree(schema);

    checker.checkSyntax(pointers, report, tree);

    final List<JsonPointer> expected = Lists.newArrayList();
    for (final JsonNode node : expectedPointers)
        expected.add(new JsonPointer(node.textValue()));

    assertEquals(pointers, expected);//w ww . jav  a  2s  .c  o  m
}

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

public Context(JsonNode jsonNode) throws MalformedURLException, URISyntaxException {
    this();/*from   ww  w .  ja v  a2  s  .c  o m*/

    JsonNode registrationNode = jsonNode.path("registration");
    if (!registrationNode.isMissingNode()) {
        this.setRegistration(UUID.fromString(registrationNode.textValue()));
    }

    // TODO: check these for Group
    JsonNode instructorNode = jsonNode.path("instructor");
    if (!instructorNode.isMissingNode()) {
        this.setInstructor(Agent.fromJson(instructorNode));
    }

    JsonNode teamNode = jsonNode.path("team");
    if (!teamNode.isMissingNode()) {
        this.setTeam(Agent.fromJson(teamNode));
    }

    JsonNode contextActivitiesNode = jsonNode.path("contextActivities");
    if (!contextActivitiesNode.isMissingNode()) {
        this.setContextActivities(new ContextActivities(contextActivitiesNode));
    }

    JsonNode revisionNode = jsonNode.path("revision");
    if (!revisionNode.isMissingNode()) {
        this.setRevision(revisionNode.textValue());
    }

    JsonNode platformNode = jsonNode.path("platform");
    if (!platformNode.isMissingNode()) {
        this.setPlatform(platformNode.textValue());
    }

    JsonNode languageNode = jsonNode.path("language");
    if (!languageNode.isMissingNode()) {
        this.setLanguage(languageNode.textValue());
    }

    JsonNode statementNode = jsonNode.path("statement");
    if (!statementNode.isMissingNode()) {
        this.setStatement(new StatementRef(statementNode));
    }

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