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:org.gitana.platform.client.support.Response.java

public List<ObjectNode> getObjectNodes() {
    List<ObjectNode> objectNodes = new ArrayList<ObjectNode>();

    ArrayNode arrayNode = (ArrayNode) getObjectNode().get(FIELD_ROWS);
    if (arrayNode != null) {
        for (int i = 0; i < arrayNode.size(); i++) {
            ObjectNode objectNode = (ObjectNode) arrayNode.get(i);
            objectNodes.add(objectNode);
        }/*  w w w.  j  a  va  2  s  .  com*/
    }

    return objectNodes;
}

From source file:org.gitana.platform.client.changeset.ChangesetImpl.java

@Override
public List<String> getParentChangesetIds() {
    List<String> parentChangesetIds = new ArrayList<String>();

    if (has(FIELD_PARENTS)) {
        ArrayNode parents = getArray(FIELD_PARENTS);
        if (parents.size() > 0) {
            for (int i = 0; i < parents.size(); i++) {
                parentChangesetIds.add(parents.get(i).textValue());
            }//  w  w  w.j a v a 2 s  . c om
        }
    }

    return parentChangesetIds;
}

From source file:com.basho.riak.client.api.commands.itest.ITestBucketMapReduce.java

private void JsBucketMR(String bucketType) throws InterruptedException, ExecutionException {
    initValues(bucketType);//from w w  w  .  j a  v  a2 s  .  co  m

    Namespace ns = new Namespace(bucketType, mrBucketName);
    BucketMapReduce bmr = new BucketMapReduce.Builder().withNamespace(ns)
            .withMapPhase(Function.newNamedJsFunction("Riak.mapValuesJson"), false)
            .withReducePhase(Function.newNamedJsFunction("Riak.reduceNumericSort"), true).build();

    RiakFuture<MapReduce.Response, BinaryValue> future = client.executeAsync(bmr);

    future.await();
    assertTrue("Map reduce operation Operation failed:" + future.cause(), future.isSuccess());

    MapReduce.Response response = future.get();

    // The query should return one phase result which is a JSON array containing
    // all the values, 0 - 199
    assertEquals(200, response.getResultsFromAllPhases().size());
    ArrayNode result = response.getResultForPhase(1);
    assertEquals(200, result.size());

    assertEquals(42, result.get(42).asInt());
    assertEquals(199, result.get(199).asInt());

    resetAndEmptyBucket(ns);
}

From source file:com.basho.riak.client.api.commands.itest.ITestBucketMapReduce.java

@Test
public void multiPhaseResult() throws InterruptedException, ExecutionException {
    initValues(Namespace.DEFAULT_BUCKET_TYPE);

    Namespace ns = new Namespace(Namespace.DEFAULT_BUCKET_TYPE, mrBucketName);
    BucketMapReduce bmr = new BucketMapReduce.Builder().withNamespace(ns)
            .withMapPhase(Function.newNamedJsFunction("Riak.mapValuesJson"), true)
            .withReducePhase(Function.newNamedJsFunction("Riak.reduceNumericSort"), true).build();

    RiakFuture<MapReduce.Response, BinaryValue> future = client.executeAsync(bmr);

    future.await();/*from   w w w .  ja va  2  s  .com*/
    assertTrue(future.isSuccess());

    MapReduce.Response response = future.get();

    // The query should return two phase results, each a JSON array containing
    // all the values, 0 - 199
    assertEquals(400, response.getResultsFromAllPhases().size());
    assertEquals(200, response.getResultForPhase(0).size());
    ArrayNode result = response.getResultForPhase(1);
    assertEquals(200, result.size());

    assertEquals(42, result.get(42).asInt());
    assertEquals(199, result.get(199).asInt());

    resetAndEmptyBucket(ns);
}

From source file:com.jaspersoft.studio.data.querydesigner.json.JsonDataManager.java

private List<JRDesignField> getFieldsFromArrayNode(ArrayNode node) {
    // Assumption: consider the first element as template 
    JsonNode firstEl = node.get(0);
    if (firstEl instanceof ObjectNode) {
        return getFieldsFromObjectNode((ObjectNode) firstEl);
    } else if (firstEl instanceof ArrayNode) {
        return getFieldsFromArrayNode((ArrayNode) firstEl);
    }//from  ww w  .j av a2s  . c o m
    return new ArrayList<JRDesignField>();
}

From source file:org.apache.streams.json.JsonPathFilter.java

@Override
public List<StreamsDatum> process(StreamsDatum entry) {

    List<StreamsDatum> result = Lists.newArrayList();

    String json = null;/*from w  ww  .j  av a  2s . c o  m*/

    ObjectNode document = null;

    LOGGER.debug("{} processing {}", STREAMS_ID);

    if (entry.getDocument() instanceof ObjectNode) {
        document = (ObjectNode) entry.getDocument();
        try {
            json = mapper.writeValueAsString(document);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    } else if (entry.getDocument() instanceof String) {
        json = (String) entry.getDocument();
        try {
            document = mapper.readValue(json, ObjectNode.class);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    Preconditions.checkNotNull(document);

    if (StringUtils.isNotEmpty(json)) {

        Object srcResult = null;
        try {
            srcResult = jsonPath.read(json);

        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.warn(e.getMessage());
        }

        Preconditions.checkNotNull(srcResult);

        String[] path = StringUtils.split(pathExpression, '.');
        ObjectNode node = document;
        for (int i = 1; i < path.length - 1; i++) {
            node = (ObjectNode) document.get(path[i]);
        }

        Preconditions.checkNotNull(node);

        if (srcResult instanceof JSONArray) {
            try {
                ArrayNode jsonNode = mapper.convertValue(srcResult, ArrayNode.class);
                if (jsonNode.size() == 1) {
                    JsonNode item = jsonNode.get(0);
                    node.set(destNodeName, item);
                } else {
                    node.set(destNodeName, jsonNode);
                }
            } catch (Exception e) {
                LOGGER.warn(e.getMessage());
            }
        } else if (srcResult instanceof JSONObject) {
            try {
                ObjectNode jsonNode = mapper.convertValue(srcResult, ObjectNode.class);
                node.set(destNodeName, jsonNode);
            } catch (Exception e) {
                LOGGER.warn(e.getMessage());
            }
        } else if (srcResult instanceof String) {
            try {
                node.put(destNodeName, (String) srcResult);
            } catch (Exception e) {
                LOGGER.warn(e.getMessage());
            }
        }

    }

    result.add(new StreamsDatum(document));

    return result;

}

From source file:net.maurerit.zkb.KillParser.java

private List<Item> parseItems(TreeNode node) {
    List<Item> items = new ArrayList<Item>();

    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;

        for (int idx = 0; idx < arrayNode.size(); idx++) {
            JsonNode nodeCasted = (JsonNode) arrayNode.get(idx);
            Item item = new Item();

            item.setTypeId(intFromText(nodeCasted.get(TYPE_ID_KEY)));
            item.setTypeName(TypeID.getTypeName(intFromText(nodeCasted.get(TYPE_ID_KEY))));
            item.setFlag(intFromText(nodeCasted.get(FLAG_KEY)));
            item.setQtyDropped(intFromText(nodeCasted.get(QTY_DROPPED_KEY)));
            item.setQtyDestroyed(intFromText(nodeCasted.get(QTY_DESTROYED_KEY)));

            items.add(item);/*from   ww  w  .  j  av  a  2 s.c o  m*/
        }
    }

    return items;
}

From source file:net.maurerit.zkb.KillParser.java

private List<Attacker> parseAttackers(TreeNode node) {
    List<Attacker> attackers = new ArrayList<Attacker>();

    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;

        for (int idx = 0; idx < arrayNode.size(); idx++) {
            JsonNode attackerNode = arrayNode.get(idx);
            Attacker attacker = new Attacker();

            attacker.setCharacterId(intFromText(attackerNode.get(CHAR_ID_KEY)));
            attacker.setCharacterName(attackerNode.get(CHAR_NAME_KEY).asText());
            attacker.setCorporationId(intFromText(attackerNode.get(CORP_ID_KEY)));
            attacker.setCorporationName(attackerNode.get(CORP_NAME_KEY).asText());
            attacker.setAllianceId(intFromText(attackerNode.get(ALLIANCE_ID_KEY)));
            attacker.setAllianceName(attackerNode.get(ALLIANCE_NAME_KEY).asText());
            attacker.setFactionId(intFromText(attackerNode.get(FACTION_ID_KEY)));
            attacker.setFactionName(attackerNode.get(FACTION_NAME_KEY).asText());
            attacker.setSecurityStatus(doubleFromText(attackerNode.get(SEC_STATUS_KEY)));
            attacker.setDamageDone(longFromText(attackerNode.get(DAMAGE_DONE_KEY)));
            attacker.setFinalBlow(booleanFromText(attackerNode.get(FINAL_BLOW_KEY)));
            attacker.setWeaponTypeId(intFromText(attackerNode.get(WEAPON_TYPE_KEY)));
            attacker.setWeaponName(TypeID.getTypeName(intFromText(attackerNode.get(WEAPON_TYPE_KEY))));
            attacker.setShipTypeId(intFromText(attackerNode.get(SHIP_TYPE_KEY)));
            attacker.setShipName(TypeID.getTypeName(intFromText(attackerNode.get(SHIP_TYPE_KEY))));

            attackers.add(attacker);/*from w w w  .j a v  a2  s . com*/
        }
    }

    return attackers;
}

From source file:com.turn.shapeshifter.NamedSchemaSerializerTest.java

@Test
public void testSerializeWithRepeatedTransform() throws Exception {
    NamedSchema schema = NamedSchema.of(Union.getDescriptor(), "Union").transform("int32_repeated", TWO);
    SchemaRegistry registry = new SchemaRegistry();
    registry.register(schema);/* ww  w. ja  v a 2 s. co m*/
    Union fibonacci = Union.newBuilder().addInt32Repeated(1).addInt32Repeated(1).addInt32Repeated(2)
            .addInt32Repeated(3).addInt32Repeated(5).addInt32Repeated(8).build();
    JsonNode result = new NamedSchemaSerializer(schema).serialize(fibonacci, registry);
    Assert.assertTrue(result.isObject());
    ArrayNode array = (ArrayNode) result.get("int32Repeated");
    Assert.assertEquals(2, array.get(0).asInt());
    Assert.assertEquals(2, array.get(1).asInt());
    Assert.assertEquals(4, array.get(2).asInt());
    Assert.assertEquals(6, array.get(3).asInt());
    Assert.assertEquals(10, array.get(4).asInt());
    Assert.assertEquals(16, array.get(5).asInt());
}

From source file:org.apache.flink.test.web.WebFrontendITCase.java

@Test
public void getTaskManagerLogAndStdoutFiles() {
    try {//from   www.j  a v a 2s  .c o m
        String json = getFromHTTP("http://localhost:" + port + "/taskmanagers/");

        ObjectMapper mapper = new ObjectMapper();
        JsonNode parsed = mapper.readTree(json);
        ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers");
        JsonNode taskManager = taskManagers.get(0);
        String id = taskManager.get("id").asText();

        WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation
                .find(cluster.configuration());

        //we check for job manager log files, since no separate taskmanager logs exist
        FileUtils.writeStringToFile(logFiles.logFile, "job manager log");
        String logs = getFromHTTP("http://localhost:" + port + "/taskmanagers/" + id + "/log");
        assertTrue(logs.contains("job manager log"));

        FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out");
        logs = getFromHTTP("http://localhost:" + port + "/taskmanagers/" + id + "/stdout");
        assertTrue(logs.contains("job manager out"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}