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:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java

private UpdateCondition getUpdateCondition(ObjectNode expectNode) {
    String nameParameter = expectNode.get("name").asText();
    String valueParameter = null;
    Boolean existsParameter = null;

    if (null != expectNode.get("value"))
        valueParameter = expectNode.get("value").asText();

    if (null != expectNode.get("exists"))
        existsParameter = Boolean.valueOf("" + expectNode.get("exists"));

    return new UpdateCondition(nameParameter, valueParameter, existsParameter);
}

From source file:com.ibm.alchemy.api.EntitiesProcessor.java

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

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

    ObjectNode rootDocument = getRootDocument(entry);

    if (!rootDocument.has("links") || !rootDocument.get("links").isArray()
            || ((ArrayNode) (rootDocument.get("links"))).size() == 0)

        return Lists.newArrayList();

    else//from  w ww .  j  a v  a2  s  . c  o  m

        return super.process(entry);

}

From source file:models.protocol.v1.HeartbeatMessagesProcessor.java

/**
 * {@inheritDoc}//from w ww . j a va  2 s .  co m
 */
@Override
public boolean handleMessage(final Object message) {
    if (message instanceof Command) {
        _metrics.incrementCounter(HEARTBEAT_COUNTER);
        //TODO(barp): Map with a POJO mapper [MAI-184]
        final Command command = (Command) message;
        final ObjectNode commandNode = (ObjectNode) command.getCommand();
        final String commandString = commandNode.get("command").asText();
        if (COMMAND_HEARTBEAT.equals(commandString)) {
            _connectionContext.getConnection().write(OK_RESPONSE);
            return true;
        }
    }
    return false;
}

From source file:com.arpnetworking.metrics.proxy.models.protocol.v1.HeartbeatMessagesProcessor.java

/**
 * {@inheritDoc}/*from   w w w .ja v a  2s.c om*/
 */
@Override
public boolean handleMessage(final Object message) {
    if (message instanceof Command) {
        _metrics.incrementCounter(HEARTBEAT_COUNTER);
        //TODO(barp): Map with a POJO mapper [MAI-184]
        final Command command = (Command) message;
        final ObjectNode commandNode = (ObjectNode) command.getCommand();
        final String commandString = commandNode.get("command").asText();
        if (COMMAND_HEARTBEAT.equals(commandString)) {
            _connection.send(OK_RESPONSE);
            return true;
        }
    }
    return false;
}

From source file:org.fusesource.restygwt.examples.server.GreetingServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    System.out.println("Creating custom greeting.");
    try {/*from w w w.j a va2s  .co  m*/
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode nameObject = mapper.readValue(req.getInputStream(), ObjectNode.class);
        String name = nameObject.get("name").asText();

        String greeting = "Hello " + name;
        ObjectNode resultObject = new ObjectNode(JsonNodeFactory.instance);
        resultObject.put("greeting", greeting);
        mapper.writeValue(resp.getOutputStream(), resultObject);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        System.out.flush();
        System.err.flush();
    }
}

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:controllers.TelemetryController.java

/**
 * Store new aggregated metrics for streaming to clients.
 *
 * @return Empty response with success/error code.
 *///  w  ww  .j  a va 2  s .c om
@BodyParser.Of(Json.class)
public Result report() {
    // TODO(barp): Map with a POJO mapper [MAI-184]

    final ArrayNode list = (ArrayNode) request().body().asJson();
    for (final JsonNode objNode : list) {
        final ObjectNode obj = (ObjectNode) objNode;
        final String service = obj.get("service").asText();
        final String host = obj.get("host").asText();
        final String statistic = obj.get("statistic").asText();
        final String metric = obj.get("metric").asText();
        final double value = obj.get("value").asDouble();
        final String periodStart = obj.get("periodStart").asText();
        final DateTime startTime = DateTime.parse(periodStart);

        _streamContext.tell(new MetricReport(service, host, statistic, metric, value, startTime),
                ActorRef.noSender());
    }

    return ok();
}

From source file:com.almende.eve.agent.google.GoogleCalculatorAgent.java

/**
 * Evaluate given expression/*from  w ww .ja  va2s .  co  m*/
 * For example expr="2.5 + 3 / sqrt(16)" will return "3.25"
 * 
 * @param expr
 *            the expr
 * @return result
 * @throws Exception
 *             the exception
 */
public String eval(@Name("expr") final String expr) throws Exception {
    final String url = CALC_API_URL + "?q=" + URLEncoder.encode(expr, "UTF-8");
    String resp = HttpUtil.get(url);

    // the field names in resp are not enclosed by quotes :(
    resp = resp.replaceAll("lhs:", "\"lhs\":");
    resp = resp.replaceAll("rhs:", "\"rhs\":");
    resp = resp.replaceAll("error:", "\"error\":");
    resp = resp.replaceAll("icc:", "\"icc\":");

    final ObjectMapper mapper = JOM.getInstance();
    final ObjectNode json = mapper.readValue(resp, ObjectNode.class);

    final String error = json.get("error").asText();
    if (error != null && !error.isEmpty()) {
        throw new Exception(error);
    }

    final String rhs = json.get("rhs").asText();
    return rhs;
}

From source file:com.redhat.lightblue.Request.java

/**
 * Parses the entity, client identification and execution options from the
 * given json object/*from w  ww  . jav  a  2s  . c om*/
 */
protected void parse(ObjectNode node) {
    entityVersion = new EntityVersion();
    JsonNode x = node.get("entity");
    if (x != null) {
        entityVersion.setEntity(x.asText());
    }
    x = node.get("entityVersion");
    if (x != null) {
        entityVersion.setVersion(x.asText());
    }
    // TODO: clientIdentification
    x = node.get("execution");
    if (x != null) {
        execution = ExecutionOptions.fromJson((ObjectNode) x);
    }
}

From source file:com.ikanow.aleph2.graph.titan.services.SimpleGraphMergeService.java

@Override
public void onObjectBatch(Stream<Tuple2<Long, IBatchRecord>> batch, Optional<Integer> batch_size,
        Optional<JsonNode> grouping_key) {

    // (some horrible mutable state to keep this simple)
    final LinkedList<Tuple2<Long, IBatchRecord>> mutable_user_elements = new LinkedList<>();

    final Optional<Validation<BasicMessageBean, JsonNode>> output = batch.filter(t2 -> {
        if (!t2._2().injected() && mutable_user_elements.isEmpty()) { // (save one element per label in case there are no injected elements)
            mutable_user_elements.add(t2);
        }// w ww .  j  a v  a  2 s.  c o  m
        return t2._2().injected();
    }).filter(t2 -> {
        final ObjectNode o = (ObjectNode) t2._2().getJson();
        return Optional.ofNullable(o.get(GraphAnnotationBean.type)).filter(j -> (null != j) && j.isTextual())
                .map(j -> j.asText()).map(type -> {
                    if (GraphAnnotationBean.ElementType.edge.toString().equals(type)) {
                        // Return the first matching edge:
                        return true;
                    } else if (GraphAnnotationBean.ElementType.vertex.toString().equals(type)) {
                        // Return the first matching vertex:
                        return true;
                    } else
                        return false;
                }).orElse(false);
    }).findFirst().<Validation<BasicMessageBean, JsonNode>>map(
            element -> _context.get().emitImmutableObject(_context.get().getNextUnusedId(),
                    element._2().getJson(), Optional.empty(), Optional.empty(), Optional.empty()));

    if (!output.isPresent()) { // If didn't find any matching elements, then stick the first one we did find in there
        mutable_user_elements.forEach(t2 -> _context.get().emitImmutableObject(t2._1(), t2._2().getJson(),
                Optional.empty(), Optional.empty(), Optional.empty()));
    }
}