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.reprezen.swagedit.schema.ComplexTypeDefinition.java

private void init() {
    final ArrayNode container = (ArrayNode) content.get(type.getValue());

    for (int i = 0; i < container.size(); i++) {
        JsonNode current = container.get(i);
        TypeDefinition def = schema.createType(this, type.getValue() + "/" + i, current);
        if (def != null) {
            complexTypes.add(def);/*w ww.  j  a va  2 s . c om*/
        }
    }
}

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

@Test
public void analysisWithManyArtefactsAndManyViolations() throws IOException {
    Artefact artefact1 = new Artefact("project.A", "DUMMY");
    Artefact artefact2 = new Artefact("project.B", "DUMMY");
    Artefact artefact3 = new Artefact("project.test.util.C", "DUMMY");
    Artefact artefact4 = new Artefact("project.test.util.D", "DUMMY");
    Artefact artefact5 = new Artefact("E", "DUMMY");

    artefact1.setChangeProbability(0.1);
    artefact2.setChangeProbability(0.2);
    artefact3.setChangeProbability(0.3);
    artefact4.setChangeProbability(0.4);
    artefact5.setChangeProbability(0.5);

    QualityViolation violation1 = new QualityViolation(artefact1, null, 0, 0, 0, "");
    QualityViolation violation2 = new QualityViolation(artefact2, null, 0, 0, 0, "");
    QualityViolation violation3 = new QualityViolation(artefact3, null, 0, 0, 0, "");
    QualityViolation violation4 = new QualityViolation(artefact4, null, 0, 0, 0, "");
    QualityViolation violation5 = new QualityViolation(artefact5, null, 0, 0, 0, "");

    QualityAnalysis analysis = QualityAnalysis.success(project,
            Arrays.asList(violation1, violation2, violation3, violation4, violation5));

    when(weightedProfitCalculator.calculateWeightedProfit(violation1)).thenReturn(10.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation2)).thenReturn(20.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation3)).thenReturn(30.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation4)).thenReturn(40.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation5)).thenReturn(50.0);

    JsonNode generatedJson = generate(analysis);
    ArrayNode rootPackagNode = (ArrayNode) generatedJson.get("children");
    assertThat(rootPackagNode.get(1).get("changeProbability").asInt()).isEqualTo(22);
}

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

@Test
public void profitablePacakgesAndArtefactsShouldBeFilteredProperly() throws IOException {
    Artefact artefact1 = new Artefact("org.project.test.util.C", "DUMMY");
    Artefact artefact2 = new Artefact("org.project.test.util.D", "DUMMY");
    Artefact artefact3 = new Artefact("org.project.test.E", "DUMMY");
    Artefact artefact4 = new Artefact("org.project.F", "DUMMY");

    artefact1.setChangeProbability(0.1);
    artefact1.setManualEstimate(40);//from   ww  w  .j a  va2 s .  co  m

    artefact2.setChangeProbability(0.2);
    artefact2.setManualEstimate(80);

    artefact3.setChangeProbability(0.0);
    artefact4.setChangeProbability(0.0);

    QualityViolation violation1 = new QualityViolation(artefact1, null, 0, 0, 0, "");
    QualityViolation violation2 = new QualityViolation(artefact2, null, 0, 0, 0, "");
    QualityViolation violation3 = new QualityViolation(artefact3, null, 0, 0, 0, "");
    QualityViolation violation4 = new QualityViolation(artefact4, null, 0, 0, 0, "");

    QualityAnalysis analysis = QualityAnalysis.success(project,
            Arrays.asList(violation1, violation2, violation3, violation4));

    when(weightedProfitCalculator.calculateWeightedProfit(violation1)).thenReturn(10.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation2)).thenReturn(20.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation3)).thenReturn(-10.0);
    when(weightedProfitCalculator.calculateWeightedProfit(violation4)).thenReturn(-20.0);

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

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeReplaceLiteralWithArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("\"foo\"").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(1, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeReplaceObjectNodeWithArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("{\"a\":\"1\"}").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(1, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeArrayNodeAndArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"2\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(2, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
    Assert.assertEquals("2", arrayNode.get(1).asText());
}

From source file:io.wcm.caravan.pipeline.impl.operators.ExtractOperator.java

@Override
public Subscriber<? super JsonPipelineOutput> call(Subscriber<? super JsonPipelineOutput> subscriber) {
    return new Subscriber<JsonPipelineOutput>() {

        @Override/*from w  ww .  j  a  v  a 2s.c o m*/
        public void onCompleted() {
            subscriber.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            Exceptions.throwIfFatal(e);
            subscriber.onError(e);
        }

        @Override
        public void onNext(JsonPipelineOutput output) {
            ArrayNode result = new JsonPathSelector(jsonPath).call(output.getPayload());

            JsonNode extractedPayload = result.size() == 0 ? MissingNode.getInstance() : result.get(0);

            if (isNotBlank(targetProperty)) {
                extractedPayload = JacksonFunctions.wrapInObject(targetProperty, extractedPayload);
            }

            JsonPipelineOutput extractedOutput = output.withPayload(extractedPayload);
            subscriber.onNext(extractedOutput);
        }
    };
}

From source file:org.emfjson.jackson.tests.uuids.UuidSaveTest.java

@Test
public void testSerializeOneRootWithTwoChildHavingOneReference() throws IOException {
    Resource resource = createUuidResource("test.xmi", mapper);

    Container root = ModelFactory.eINSTANCE.createContainer();
    ConcreteTypeOne one = ModelFactory.eINSTANCE.createConcreteTypeOne();
    ConcreteTypeOne two = ModelFactory.eINSTANCE.createConcreteTypeOne();

    one.setName("one");
    two.setName("two");

    one.getRefProperty().add(two);/*from  www.j  ava2  s.  c om*/

    root.getElements().add(one);
    root.getElements().add(two);

    resource.getContents().add(root);

    JsonNode node = mapper.valueToTree(root);

    assertNotNull(node);
    assertNotNull(node.get("@id"));
    assertEquals(uuid(root), uuid(node));

    assertTrue(node.get("elements").isArray());

    ArrayNode elements = (ArrayNode) node.get("elements");
    assertEquals(2, elements.size());

    JsonNode node1 = elements.get(0);
    JsonNode node2 = elements.get(1);

    assertNotNull(node1.get("@id"));
    assertEquals(uuid(one), uuid(node1));

    assertNotNull(node2.get("@id"));
    assertEquals(uuid(two), uuid(node2));

    assertNotNull(node1.get("refProperty"));
    assertNull(node2.get("refProperty"));
    assertTrue(node1.get("refProperty").isArray());

    ArrayNode refProperty = (ArrayNode) node1.get("refProperty");
    assertEquals(1, refProperty.size());

    JsonNode ref = refProperty.get(0);
    assertNotNull(ref.get("$ref"));

    assertEquals(uuid(two), ref.get("$ref").asText());
}

From source file:org.gitana.platform.client.job.JobLogEntry.java

public List<String> getStackTrace() {
    List<String> list = new ArrayList<String>();

    if (has(FIELD_STACKTRACE)) {
        ArrayNode array = getArray(FIELD_STACKTRACE);
        for (int i = 0; i < array.size(); i++) {
            String element = (String) array.get(i).textValue();

            list.add(element);//w w  w  . ja  v  a 2 s  .  c o  m
        }
    }

    return list;
}

From source file:de.thingweb.client.ClientFactory.java

protected Client pickClient() throws UnsupportedException, URISyntaxException {
    // check for right protocol&encoding
    List<Client> clients = new ArrayList<>(); // it is assumed URIs are ordered by priority

    JsonNode uris = thing.getMetadata().get("uris");
    if (uris != null) {
        if (uris.getNodeType() == JsonNodeType.STRING) {
            checkUri(uris.asText(), clients);
        } else if (uris.getNodeType() == JsonNodeType.ARRAY) {
            ArrayNode an = (ArrayNode) uris;
            for (int i = 0; i < an.size(); i++) {
                checkUri(an.get(i).asText(), i, clients);
            }/*from   w w w.  j a  v a  2 s . co m*/
        }

        // int prio = 1;
        //      for (JsonNode juri : uris) {
        //       String suri = juri.asText();
        //        URI uri = new URI(suri);
        //        if(isCoapScheme(uri.getScheme())) {
        //          clients.add(new CoapClientImpl(suri, thing));
        //          log.info("Found matching client '" + CoapClientImpl.class.getName() + "' with priority " + prio++);
        //        } else if(isHttpScheme(uri.getScheme())) {
        //          clients.add(new HttpClientImpl(suri, thing));
        //          log.info("Found matching client '" + HttpClientImpl.class.getName() + "' with priority " + prio++);
        //        } 
        //      }
    }

    // take priority into account
    if (clients.isEmpty()) {
        log.warn("No fitting client implementation found!");
        throw new UnsupportedException("No fitting client implementation found!");
        // return null;
    } else {
        // pick first one with highest priority
        Client c = clients.get(0);
        log.info("Use '" + c.getClass().getName() + "' according to priority");
        return c;
    }

}