Example usage for com.fasterxml.jackson.databind.node ArrayNode get

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.github.pjungermann.config.types.json.JsonConverterTest.java

@Test
@SuppressWarnings({ "unchecked", "RedundantCast" })
public void to_flatConfig_hierarchicalJsonObject() throws ConfigConversionException {
    Config config = new Config();
    config.put("boolean_true", true);
    config.put("boolean_false", false);
    config.put("number", 123456);
    config.put("string", "string value");
    config.put("level_1.level_2.an", "entry");
    config.put("level_1.another", "value");
    config.put("list", Arrays.asList(1, 2, 3));

    ObjectNode json = converter.to(config);

    assertEquals(true, ((BooleanNode) json.get("boolean_true")).booleanValue());
    assertEquals(false, ((BooleanNode) json.get("boolean_false")).booleanValue());
    assertEquals(123456, ((IntNode) json.get("number")).intValue());
    assertEquals("string value", ((TextNode) json.get("string")).textValue());
    ObjectNode level1 = (ObjectNode) json.get("level_1");
    ObjectNode level2 = (ObjectNode) level1.get("level_2");
    assertEquals("value", ((TextNode) level1.get("another")).textValue());
    assertEquals("entry", ((TextNode) level2.get("an")).textValue());
    ArrayNode list = (ArrayNode) json.get("list");
    assertEquals(1, ((IntNode) list.get(0)).intValue());
    assertEquals(2, ((IntNode) list.get(1)).intValue());
    assertEquals(3, ((IntNode) list.get(2)).intValue());
}

From source file:org.pac4j.oauth.client.VkClient.java

@Override
protected VkProfile extractUserProfile(final String body) {
    final VkProfile profile = new VkProfile();
    JsonNode json = JsonHelper.getFirstNode(body);
    if (json != null) {
        ArrayNode array = (ArrayNode) json.get("response");
        JsonNode userNode = array.get(0);
        profile.setId(JsonHelper.get(userNode, "uid"));
        for (final String attribute : OAuthAttributesDefinitions.vkDefinition.getAllAttributes()) {
            profile.addAttribute(attribute, JsonHelper.get(userNode, attribute));
        }/*ww  w  .jav a2  s  .c o m*/
    }
    return profile;
}

From source file:org.gitana.platform.client.log.LogThrowable.java

public List<LogStackTraceElement> getStackTrace() {
    List<LogStackTraceElement> stacktrace = new ArrayList<LogStackTraceElement>();

    ArrayNode array = (ArrayNode) getObject().get(FIELD_STACKTRACE);
    for (int i = 0; i < array.size(); i++) {
        ObjectNode object = (ObjectNode) array.get(i);

        stacktrace.add(new LogStackTraceElement(object));
    }// www.  ja va2  s  .  c om

    return stacktrace;
}

From source file:org.gitana.platform.client.transfer.CopyJob.java

public List<TransferImport> getImports() {
    List<TransferImport> imports = new ArrayList<TransferImport>();

    ArrayNode array = getArray(FIELD_IMPORTS);
    for (int i = 0; i < array.size(); i++) {
        ObjectNode object = (ObjectNode) array.get(i);

        TransferDependencyChain sources = TransferDependencyChain.create((ArrayNode) object.get("sources"));
        TransferDependencyChain targets = TransferDependencyChain.create((ArrayNode) object.get("targets"));

        TransferImport transferImport = new TransferImport(sources, targets);
        imports.add(transferImport);//w  ww .  jav a 2s. c o m
    }

    return imports;
}

From source file:org.gitana.platform.client.permission.PermissionCheckResults.java

public synchronized Map<String, PermissionCheckResult> map() {
    if (map == null) {
        Map<String, PermissionCheckResult> theMap = new HashMap<String, PermissionCheckResult>();

        ArrayNode array = (ArrayNode) getObject().get("results");
        for (int i = 0; i < array.size(); i++) {
            ObjectNode object = (ObjectNode) array.get(i);

            PermissionCheckResult result = new PermissionCheckResult(object);

            String key = result.getPermissionedId() + "_" + result.getPrincipalId() + "_"
                    + result.getPermissionId();

            theMap.put(key, result);/*  w  w w .ja v  a  2  s  . c o  m*/
        }

        map = theMap;
    }

    return map;
}

From source file:org.codeqinvest.web.project.InvestmentOpportunitiesJsonGeneratorTest.java

@Test
public void analysisWithOneArtefact() throws IOException {
    Artefact artefact = new Artefact("org.project.MyClass", "DUMMY");
    artefact.setChangeProbability(0.6);//from  w w w . j av  a 2  s  .  c o m
    QualityViolation violation = new QualityViolation(artefact, null, 5, 10, 0, "");
    QualityAnalysis analysis = QualityAnalysis.success(project, Arrays.asList(violation));

    when(weightedProfitCalculator.calculateWeightedProfit(violation)).thenReturn(1234.0);

    JsonNode generatedJson = generate(analysis);
    ArrayNode rootPackagNode = (ArrayNode) generatedJson.get("children");
    assertThat(rootPackagNode.get(0).get("changeProbability").asInt()).isEqualTo(60);
    assertThat(rootPackagNode.get(0).get("children").get(0).get("children").get(0).get("value").asDouble())
            .isEqualTo(1234.0);
}

From source file:de.jlo.talendcomp.json.JsonComparator.java

/**
 * Checks if the array contains the given value
 * @param array the array which perhaps contains the value
 * @param value the value to search for//from   w ww . ja va2  s.  co  m
 * @return true or false
 */
public boolean contains(ArrayNode array, JsonNode value) {
    for (int i = 0, n = array.size(); i < n; i++) {
        JsonNode node = array.get(i);
        if (node.equals(value)) {
            return true;
        }
    }
    return false;
}

From source file:com.mapr.data.sputnik.util.JsonUtils.java

public void flattenJsonIntoMap(String currentPath, JsonNode jsonNode, Map<String, Object> map) {
    if (jsonNode.isObject()) {
        ObjectNode objectNode = (ObjectNode) jsonNode;
        Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
        String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";

        while (iter.hasNext()) {
            Map.Entry<String, JsonNode> entry = iter.next();
            flattenJsonIntoMap(pathPrefix + entry.getKey(), entry.getValue(), map);
        }/* w  w w .j  av a  2 s  . c o m*/
    } else if (jsonNode.isArray()) {
        ArrayNode arrayNode = (ArrayNode) jsonNode;
        for (int i = 0; i < arrayNode.size(); i++) {
            flattenJsonIntoMap(currentPath + "[" + i + "]", arrayNode.get(i), map);
        }
    } else if (jsonNode.isValueNode()) {
        ValueNode valueNode = (ValueNode) jsonNode;
        Object value = null;
        if (valueNode.isNumber()) {
            value = valueNode.numberValue();
        } else if (valueNode.isBoolean()) {
            value = valueNode.asBoolean();
        } else if (valueNode.isTextual()) {
            value = valueNode.asText();
        }
        map.put(currentPath, value);
    }
}

From source file:me.tfeng.toolbox.dust.NodeEngine.java

private JsonNode evaluate(Process process, String template, String data) throws IOException {
    PrintWriter writer = new PrintWriter(process.getOutputStream());
    writer.println("[");
    printRenderScript(writer, template, data);
    writer.println("]");
    writer.println("1");
    writer.flush();//from   w w  w  .  java 2  s. c o  m

    String result = readInput(process, "1");
    JsonParser parser = new JsonFactory().createParser(result).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,
            true);
    ArrayNode arrayNode = OBJECT_MAPPER.readValue(parser, ArrayNode.class);
    return arrayNode.get(0);
}

From source file:me.tfeng.toolbox.dust.NodeEngine.java

private boolean isRegistered(Process process, String template) throws IOException {
    PrintWriter writer = new PrintWriter(process.getOutputStream());
    writer.println("[");
    printIsRegisteredExpression(writer, template);
    writer.println("]");
    writer.println("1");
    writer.flush();/*from w w  w  . j  ava 2  s  .c o  m*/

    String result = readInput(process, "1");
    JsonParser parser = new JsonFactory().createParser(result).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,
            true);
    ArrayNode arrayNode = OBJECT_MAPPER.readValue(parser, ArrayNode.class);
    return arrayNode.get(0).booleanValue();
}