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

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

Introduction

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

Prototype

public abstract String asText();

Source Link

Usage

From source file:lumbermill.api.JsonEvent.java

public List<String> getTags() {

    if (!jsonNode.has("tags")) {
        return Collections.EMPTY_LIST;
    }//from   ww  w.j  av a  2 s.  c o  m
    ArrayNode node = (ArrayNode) jsonNode.get("tags");
    List<String> tags = new ArrayList<>();
    for (JsonNode jNode : node) {
        tags.add(jNode.asText());
    }
    return tags;
}

From source file:net.solarnetwork.node.weather.nz.metservice.MetserviceSupport.java

/**
 * Parse a Date from an attribute value.
 * // w w  w.ja va 2 s.c  o  m
 * <p>
 * If the date cannot be parsed, <em>null</em> will be returned.
 * </p>
 * 
 * @param key
 *        the attribute key to obtain from the {@code data} Map
 * @param data
 *        the attributes
 * @param dateFormat
 *        the date format to use to parse the date string
 * @return the parsed {@link Date} instance, or <em>null</em> if an error
 *         occurs or the specified attribute {@code key} is not available
 */
protected Date parseDateAttribute(String key, JsonNode data, SimpleDateFormat dateFormat) {
    Date result = null;
    if (data != null) {
        JsonNode node = data.get(key);
        if (node != null) {
            try {
                result = dateFormat.parse(node.asText());
            } catch (ParseException e) {
                log.debug("Error parsing date attribute [{}] value [{}] using pattern {}: {}",
                        new Object[] { key, data.get(key), dateFormat.toPattern(), e.getMessage() });
            }
        }
    }
    return result;
}

From source file:com.rmn.qa.servlet.BmpServlet.java

private String getJsonString(JsonNode node, String key) {
    String ret = null;//from   www .  j av  a 2  s  . co m
    JsonNode child = node.get(key);
    if (child != null) {
        ret = child.asText();
    }
    return ret;
}

From source file:com.github.mrstampy.gameboot.messages.GameBootMessageConverter.java

@SuppressWarnings("unchecked")
private <AGBM extends AbstractGameBootMessage> AGBM fromJson(byte[] message, JsonNode node)
        throws GameBootException, IOException, JsonParseException, JsonMappingException {
    JsonNode typeNode = node.get(TYPE_NODE_NAME);

    if (typeNode == null)
        fail(getResponseContext(NO_TYPE), "No type specified");

    String type = typeNode.asText();

    if (isEmpty(type))
        fail(getResponseContext(NO_TYPE), "No type specified");

    Class<?> clz = finder.findClass(type);

    if (clz == null) {
        log.error("Unknown message type {} for message {}", type, message);
        fail(getResponseContext(UNKNOWN_MESSAGE), "Unrecognized message");
    }/* w w w .  j a  v  a  2 s.  c  o m*/

    return (AGBM) mapper.readValue(message, clz);
}

From source file:lumbermill.api.JsonEvent.java

public boolean contains(String field, String value) {
    if (!jsonNode.has(field)) {
        return false;
    }/*from  ww w .ja  v a2 s  .c  om*/
    JsonNode jsonNode = this.jsonNode.get(field);
    if (jsonNode instanceof ArrayNode) {
        for (JsonNode node : jsonNode) {
            if (node.asText().equals(value)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.facebook.api.FacebookPostActivitySerializer.java

private void addObjectLink(Activity activity, JsonNode value) {
    activity.getObject().setUrl(value.asText());
}

From source file:com.evrythng.java.wrapper.mapping.Deserializer.java

protected final <X> X getFieldValue(final JsonNode node) {

    if (node == null) {
        return null;
    }/*  w  ww  . j a  va  2s .com*/
    Object value = null;
    if (node.isBoolean()) {
        value = node.asBoolean();
    }
    if (node.isNumber()) {
        value = node.asDouble();
    }
    if (node.isTextual()) {
        value = node.asText();
    }
    if (node.isArray()) {
        value = new ArrayList<>();
    }
    if (node.isObject()) {
        value = new HashMap<>();
    }
    return (X) value;
}

From source file:com.github.alexfalappa.nbspringboot.codegen.InjectSpringBootGenerator.java

private void addBom(JsonNode depsMeta, String bomId) {
    JsonNode bomInfo = depsMeta.path("boms").path(bomId);
    // create dependency management section in pom if missing
    DependencyManagement depMan = model.getProject().getDependencyManagement();
    if (depMan == null) {
        depMan = model.getFactory().createDependencyManagement();
        model.getProject().setDependencyManagement(depMan);
    }//from  ww  w  .ja v  a 2  s  .c o m
    // add a dependency with type pom and scope import
    Dependency dep = model.getFactory().createDependency();
    dep.setGroupId(bomInfo.path("groupId").asText());
    dep.setArtifactId(bomInfo.path("artifactId").asText());
    dep.setVersion(bomInfo.path("version").asText());
    dep.setType("pom");
    dep.setScope("import");
    depMan.addDependency(dep);
    // bom may require extra repositories
    if (bomInfo.hasNonNull("repositories")) {
        for (JsonNode rep : bomInfo.path("repositories")) {
            addRepository(depsMeta, rep.asText());
            addPluginRepository(depsMeta, rep.asText());
        }
    }
}

From source file:org.jsonschema2pojo.rules.DefaultRule.java

/**
 * Applies this schema rule to take the required code generation steps.
 * <p>//from  w w  w  . ja va2s  . c om
 * Default values are implemented by assigning an expression to the given
 * field (so when instances of the generated POJO are created, its fields
 * will then contain their default values).
 * <p>
 * Collections (Lists and Sets) are initialized to an empty collection, even
 * when no default value is present in the schema (node is null).
 *
 * @param nodeName
 *            the name of the property which has (or may have) a default
 * @param node
 *            the default node (may be null if no default node was present
 *            for this property)
 * @param field
 *            the Java field that has added to a generated type to represent
 *            this property
 * @return field, which will have an init expression is appropriate
 */
@Override
public JFieldVar apply(String nodeName, JsonNode node, JFieldVar field, Schema currentSchema) {

    boolean defaultPresent = node != null && isNotEmpty(node.asText());

    String fieldType = field.type().fullName();

    if (defaultPresent && !field.type().isPrimitive() && node.isNull()) {
        field.init(JExpr._null());

    } else if (fieldType.startsWith(List.class.getName())) {
        field.init(getDefaultList(field.type(), node));

    } else if (fieldType.startsWith(Set.class.getName())) {
        field.init(getDefaultSet(field.type(), node));
    } else if (fieldType.startsWith(String.class.getName()) && node != null) {
        field.init(getDefaultValue(field.type(), node));
    } else if (defaultPresent) {
        field.init(getDefaultValue(field.type(), node));

    }

    return field;
}

From source file:com.facebook.api.FacebookPostActivitySerializer.java

private void addObjectSummary(Activity activity, JsonNode value) {
    activity.getObject().setSummary(value.asText());
}