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:org.lendingclub.mercator.aws.ASGScanner.java

protected void mapAsgToElb(JsonNode elbs, String asgArn, String region) {
    long updateTs = System.currentTimeMillis();
    for (JsonNode e : elbs) {
        String elbName = e.asText();
        String elbArn = String.format("arn:aws:elasticloadbalancing:%s:%s:loadbalancer/%s", region,
                getAccountId(), elbName);

        String cypher = "match (x:AwsElb {aws_arn:{elbArn}}), (y:AwsAsg {aws_arn:{asgArn}}) "
                + "merge (y)-[r:ATTACHED_TO]-(x) set r.updateTs={updateTs}";
        getNeoRxClient().execCypher(cypher, "elbArn", elbArn, "asgArn", asgArn, "updateTs", updateTs);
    }//from   ww w .  j  a v a 2s  . c  o m
    deleteObsoleteRelationships("AwsElb", "ATTACHED_TO", asgArn, updateTs);
}

From source file:com.googlecode.jsonschema2pojo.rules.FormatRule.java

/**
 * Applies this schema rule to take the required code generation steps.
 * <p>/*w ww . ja v  a  2  s  .co m*/
 * This rule maps format values to Java types:
 * <ul>
 * <li>"format":"date-time" => {@link java.util.Date}
 * <li>"format":"date" => {@link String}
 * <li>"format":"time" => {@link String}
 * <li>"format":"utc-millisec" => <code>long</code>
 * <li>"format":"regex" => {@link java.util.regex.Pattern}
 * <li>"format":"color" => {@link String}
 * <li>"format":"style" => {@link String}
 * <li>"format":"phone" => {@link String}
 * <li>"format":"uri" => {@link java.net.URI}
 * <li>"format":"email" => {@link String}
 * <li>"format":"ip-address" => {@link String}
 * <li>"format":"ipv6" => {@link String}
 * <li>"format":"host-name" => {@link String}
 * <li>other (unrecognised format) => baseType
 * </ul>
 * 
 * @param nodeName
 *            the name of the node to which this format is applied
 * @param node
 *            the format node
 * @param baseType
 *            the type which which is being formatted e.g. for
 *            <code>{ "type" : "string", "format" : "uri" }</code> the
 *            baseType would be java.lang.String
 * @return the Java type that is appropriate for the format value
 */
@Override
public JType apply(String nodeName, JsonNode node, JType baseType, Schema schema) {

    if (node.asText().equals("date-time")) {
        return baseType.owner().ref(Date.class);

    } else if (node.asText().equals("date")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("time")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("utc-millisec")) {
        return unboxIfNecessary(baseType.owner().ref(Long.class), ruleFactory.getGenerationConfig());

    } else if (node.asText().equals("regex")) {
        return baseType.owner().ref(Pattern.class);

    } else if (node.asText().equals("color")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("style")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("phone")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("uri")) {
        return baseType.owner().ref(URI.class);

    } else if (node.asText().equals("email")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("ip-address")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("ipv6")) {
        return baseType.owner().ref(String.class);

    } else if (node.asText().equals("host-name")) {
        return baseType.owner().ref(String.class);

    } else {
        return baseType;
    }

}

From source file:net.jawr.web.resource.bundle.factory.util.JsonPropertiesSource.java

/**
 * Converts the json array node to a String
 * //from   w  ww . j a  va2 s .c om
 * @param jsonArrayNode
 *            the json array node to convert
 * @return a string corresponding to the json array node
 */
private String convertToString(JsonNode jsonArrayNode) {

    StringBuilder strBuilder = new StringBuilder();
    Iterator<JsonNode> nodeIterator = jsonArrayNode.iterator();
    while (nodeIterator.hasNext()) {
        JsonNode jsonNode = (JsonNode) nodeIterator.next();
        strBuilder.append(jsonNode.asText());
        if (nodeIterator.hasNext()) {
            strBuilder.append(ARRAY_VALUE_SEPARATOR);
        }
    }
    return strBuilder.toString();
}

From source file:org.jongo.marshall.jackson.oid.ObjectIdDeserializer.java

@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    TreeNode treeNode = jp.readValueAsTree();
    JsonNode oid = ((JsonNode) treeNode).get(MONGO_QUERY_OID);
    if (fieldIsObjectId) {
        if (oid != null) {
            return new ObjectId(oid.asText());
        } else {// www . j a  va 2  s .  co m
            return new ObjectId(((JsonNode) treeNode).asText());
        }
    } else {
        if (oid != null) {
            return oid.asText();
        } else {
            return ((JsonNode) treeNode).asText();
        }
    }
}

From source file:org.walkmod.conf.entities.JSONConfigParser.java

public String[] getFileSet(JsonNode parent) {
    String[] includes = new String[parent.size()];
    Iterator<JsonNode> includesIt = parent.iterator();
    int j = 0;/*from   w w w  .j  a  va 2  s  .c o m*/
    while (includesIt.hasNext()) {
        JsonNode item = includesIt.next();
        includes[j] = item.asText();
        j++;
    }
    return includes;
}

From source file:things.thing.ThingDeserializer.java

@Override
public Thing deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    ObjectCodec oc = jp.getCodec();//from w w  w .  jav a  2s  .  co m
    JsonNode node = null;
    node = oc.readTree(jp);

    JsonNode keyNode = node.get("key");
    String key = null;
    if (keyNode != null) {
        key = keyNode.asText();
    }

    JsonNode typeNode = node.get("type");
    String type = null;
    if (typeNode != null) {
        type = typeNode.asText();
    }

    String id = null;
    JsonNode idNode = node.get("id");
    if (idNode != null) {
        id = idNode.asText();
    }

    Thing t = new Thing();
    t.setKey(key);
    t.setId(id);
    t.setThingType(type);

    JsonNode valueNode = node.get("value");
    if (valueNode != null) {
        Object p = objectMapper.treeToValue(valueNode, tr.getTypeClass(type));
        t.setValue(p);
    }

    return t;
}

From source file:com.redhat.lightblue.util.JsonUtils.java

/**
 * An approximation of how much space will a JsonNode take in memory. Does not take jvm optimizations
 * or architecture into account. Useful only to compare JsonNodes with each other.
 *
 * @param node// w  w w .j a va  2  s .  com
 * @return
 */
public static int size(JsonNode node) {
    if (node == null) {
        return 0;
    }

    int size = 0;
    if (node instanceof ArrayNode) {
        for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) {
            size += size(elements.next());
        }
    } else if (node instanceof ObjectNode) {
        for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) {
            Map.Entry<String, JsonNode> field = fields.next();
            size += field.getKey().length();
            size += size(field.getValue());
        }
    } else if (node instanceof NumericNode) {
        size += 4;
    } else {
        size += node.asText().length();
    }
    return size;
}

From source file:com.meltmedia.jackson.crypto.EncryptWithObjectMapperTest.java

@Test
public void shouldEncryptWithSerializerAnnotation()
        throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
    SerAnnotatedWithEncrypted toEncrypt = new SerAnnotatedWithEncrypted().withValue("some value");

    ObjectNode encrypted = mapper.readValue(mapper.writeValueAsString(toEncrypt), ObjectNode.class);

    EncryptedJson result = mapper.convertValue(encrypted.get("value"), EncryptedJson.class);
    JsonNode roundTrip = service.decryptAs(result, "UTF-8", JsonNode.class);

    assertThat(roundTrip.asText(), equalTo("c29tZSB2YWx1ZQ=="));

}

From source file:org.apache.solr.kelvin.testcases.SimpleTestCase.java

public void configure(JsonNode config) throws Exception {
    JsonNode type = config.path("type");
    if (type.isMissingNode() || "SimpleTestCase".equals(type.asText())) {
        readQueries(config, "k"); //legacy
        readQueries(config, "q");
        if (queries.size() == 0)
            throw new Exception("missing q parameter for simple test case");
        if (!config.has("test") && !config.has("conditions"))
            throw new Exception("missing conditions for simple test case");

        readConditions(config, "test"); //legacy
        readConditions(config, "conditions");

    } else/*from w  w  w  . ja  va2s.com*/
        throw new Exception("trying to configure on different test type");

}

From source file:com.meltmedia.jackson.crypto.EncryptWithObjectMapperTest.java

@Test
public void shouldEncryptString() throws IOException {
    WithEncrypted toEncrypt = new WithEncrypted().withStringValue("some value");

    ObjectNode encrypted = mapper.readValue(mapper.writeValueAsString(toEncrypt), ObjectNode.class);

    assertThat("has nested value", encrypted.at("/stringValue/value").isNull(), equalTo(false));
    assertThat("nested value is encrypted", encrypted.at("/stringValue/value").asText(),
            not(containsString("some value")));

    EncryptedJson result = mapper.convertValue(encrypted.get("stringValue"), EncryptedJson.class);
    JsonNode roundTrip = service.decryptAs(result, "UTF-8", JsonNode.class);

    assertThat(roundTrip.asText(), equalTo("some value"));
}