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

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

Introduction

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

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:controllers.Features.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateName(final String name) {
    final ObjectNode newProps = (ObjectNode) request().body().asJson();
    newProps.retain("name", "description", "type");
    Promise<Boolean> nameTaken = Feature.nodes.exists(newProps);
    Promise<Boolean> updated = nameTaken.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean nameTaken) {
            if (nameTaken) {
                return Promise.pure(false);
            }//from w w  w .  ja v a 2 s .  c o  m
            ObjectNode oldProps = Json.newObject();
            oldProps.put("name", name);
            return Feature.nodes.update(oldProps, newProps);
        }
    });
    return updated.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean updated) {
            if (updated) {
                result.put("id", newProps.get("name").asText());
                result.put("message", "Name successfully updated.");
                return ok(result);
            }
            result.put("message", "Name not updated.");
            return badRequest(result);
        }
    });
}

From source file:enmasse.controller.api.v3.amqp.AmqpFlavorsApiTest.java

@Test
public void testList() throws IOException {
    Message response = doRequest("GET", "", Optional.empty());
    ObjectNode json = decodeJson(response);

    assertThat(json.get("kind").asText(), is("FlavorList"));
    assertThat(json.get("items").size(), is(2));
    assertThat(json.get("items").get(0).get("spec").get("type").asText(), is("queue"));
    assertThat(json.get("items").get(0).get("spec").get("description").asText(), is("Simple queue"));
    assertThat(json.get("items").get(1).get("spec").get("type").asText(), is("topic"));
    assertThat(json.get("items").get(1).get("spec").get("description").asText(), is("Simple topic"));
}

From source file:org.jsfr.json.provider.JacksonProvider.java

@Override
public Object resolve(ObjectNode object, String key) {
    return object.get(key);
}

From source file:org.forgerock.openig.migrate.action.model.ModelBuilder.java

public RouteModel buildRoute(ObjectNode node) {
    List<ObjectModel> objects = new ArrayList<>();
    int index = 0;
    for (JsonNode value : node.get("heap")) {
        objects.add(buildObject((ObjectNode) value, index++));
    }/* w w w .  j  a  v  a2  s  .c om*/
    return new RouteModel(node, objects);
}

From source file:com.sqs.tq.fdc.PlainTextReporter.java

@Override
public void report(ObjectNode reportData) {
    out.println();// w  ww . j a  v  a 2  s.  c  o  m
    out.println(String.format("File variants of '%s'", reportData.get("name").textValue()));
    out.println("---------------------------------------------------");

    int idx = 1;
    for (JsonNode group : (ArrayNode) reportData.get("groups")) {
        String hash = group.get("hash").textValue();
        ArrayNode files = (ArrayNode) group.get("files");
        out.println(String.format("%d) #%d times (md5: %s)", idx, files.size(), hash));
        for (JsonNode fd : files) {
            out.println(String.format("  %s", fd.textValue()));
        }
        ++idx;
    }

}

From source file:io.confluent.connect.elasticsearch.internals.Response.java

public Response(BulkResult result) {
    this.result = result;
    Throwable firstException = null;
    for (BulkResultItem bulkResultItem : result.getFailedItems()) {
        ObjectNode obj = parseError(bulkResultItem.error);
        String exceptionType = obj.get("type").asText();
        if (exceptionType.equals(nonRetriableError)) {
            throwable = new Throwable(exceptionType);
            break;
        } else {//from w  w  w  .  j  a  v a 2 s .  c  om
            if (firstException == null) {
                firstException = new Throwable(bulkResultItem.error);
            }
        }
    }
    if (throwable == null) {
        throwable = firstException;
    }
}

From source file:com.jivesoftware.os.server.http.jetty.jersey.endpoints.killswitch.KillSwitchsRestEndpointsTest.java

@Test
public void testSetKillSwitch() throws IOException {
    Mockito.when(killSwitchService.set("hi", true)).thenReturn(true);
    Response result = instance.setKillSwitch("hi", true);
    ObjectNode got = mapper.readValue(result.getEntity().toString(), ObjectNode.class);
    Assert.assertTrue(got.get("state").booleanValue());

    Mockito.when(killSwitchService.set("hi", false)).thenReturn(true);
    result = instance.setKillSwitch("hi", false);
    got = mapper.readValue(result.getEntity().toString(), ObjectNode.class);
    Assert.assertFalse(got.get("state").booleanValue());
}

From source file:com.sg2net.utilities.ListaCAP.json.ComuneDeserializer.java

@Override
public Comune deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
    ObjectNode root = (ObjectNode) mapper.readTree(jsonParser);
    JsonNode codiceIstatNode = root.get("codiceIstat");
    String codiceIstat = codiceIstatNode.asText();
    JsonNode codiceCatastaleNode = root.get("codiceCatastale");
    String codiceCatastale = codiceCatastaleNode.asText();
    JsonNode nomeNode = root.get("nome");
    String nome = nomeNode.asText();
    JsonNode provinciaNode = root.get("provincia");
    String provincia = provinciaNode.asText();
    JsonNode codiciCapNode = root.get("codiciCap");
    Collection<String> codiciCap = new ArrayList<>();
    Iterator<JsonNode> capNodes = codiciCapNode.elements();
    while (capNodes.hasNext()) {
        JsonNode codiceCapNode = capNodes.next();
        String codiceCap = codiceCapNode.asText();

        codiciCap.add(codiceCap);//from  w  w w  .ja v a 2  s  .c  o  m
    }
    Comune comune = new Comune(codiceIstat, codiceCatastale, nome, provincia);
    comune.setCodiciCap(codiciCap);
    logger.trace("comune =" + comune + " deserializzato from json");
    return comune;
}

From source file:com.almende.eve.algorithms.DAA.java

/**
 * Configure this library, using a json DOM structure to wrap the
 * configuration./*from  w ww.  j a  v  a  2 s.  c om*/
 *
 * @param config
 *            the config
 */
public void configure(ObjectNode config) {
    if (config.has("width")) {
        this.width = config.get("width").asInt();
    }
    if (config.has("initialTTL")) {
        this.initialTTL = config.get("initialTTL").asInt();
    }
    if (config.has("evictionFactor")) {
        this.evictionFactor = config.get("evictionFactor").asInt();
    }
}

From source file:com.basistech.rosette.dm.json.plain.DefaultValuesVisibleTest.java

@Test
public void checkVisible() throws Exception {
    AnnotatedText.Builder builder = new AnnotatedText.Builder();
    builder.data("George Washington slept here.");
    ListAttribute.Builder<Entity> entityListBuilder = new ListAttribute.Builder<>(Entity.class);
    //int startOffset, int endOffset, String entityType)
    Mention.Builder mentionBuilder = new Mention.Builder(0, 17);
    mentionBuilder.confidence(null); // null is the official default, but null is never rendered, default or not.
    Entity.Builder entityBuilder = new Entity.Builder();
    entityBuilder.mention(mentionBuilder.build());
    entityListBuilder.add(entityBuilder.build());
    builder.entities(entityListBuilder.build());

    AnnotatedText text = builder.build();

    ObjectMapper mapper = objectMapper();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    mapper.writeValue(byteArrayOutputStream, text); // serialize

    // now bring it back
    JsonNode tree = mapper.readTree(byteArrayOutputStream.toByteArray());
    // and navigate to the problem at hand.
    ObjectNode attrsNode = (ObjectNode) tree.get("attributes");
    ObjectNode mentionsNode = (ObjectNode) attrsNode.get(KnownAttribute.ENTITY.key());
    ObjectNode mentionNode = (ObjectNode) mentionsNode.get("items").get(0);
    assertFalse(mentionNode.has("confidence"));
}