Example usage for com.fasterxml.jackson.databind JsonNode get

List of usage examples for com.fasterxml.jackson.databind JsonNode get

Introduction

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

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:org.dd4t.databind.util.JsonUtils.java

public static TCMURI getTcmUriFromField(String fieldName, JsonNode node) {
    if (!node.has(fieldName)) {
        return null;
    }/*from   w ww .j a  v  a2s .  co m*/
    String tcmUri = node.get(fieldName).textValue();
    TCMURI uri = null;
    try {
        uri = new TCMURI(tcmUri);
    } catch (ParseException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    return uri;
}

From source file:org.dd4t.databind.util.JsonUtils.java

public static DateTime getDateFromField(String fieldName, JsonNode node) {
    if (!node.has(fieldName)) {
        return null;
    }/*w ww  .  j  ava 2 s .  c om*/
    String dateNode = node.get(fieldName).textValue();
    if (StringUtils.isEmpty(dateNode)) {
        return null;
    }

    return DateUtils.convertStringToDate(dateNode);
}

From source file:com.linecorp.armeria.server.grpc.GrpcDocServiceTest.java

private static void addExamples(JsonNode json) {
    json.get("services").forEach(service -> {
        final String serviceName = service.get("name").textValue();
        // Add the method-specific examples.
        service.get("methods").forEach(method -> {
            final String methodName = method.get("name").textValue();
            final ArrayNode exampleRequests = (ArrayNode) method.get("exampleRequests");
            if (TestServiceGrpc.SERVICE_NAME.equals(serviceName) && "UnaryCall".equals(methodName)) {
                exampleRequests//from   w w w. jav  a 2 s.  co  m
                        .add("{\n" + "  \"payload\": {\n" + "    \"body\": \"d29ybGQ=\"\n" + "  }\n" + '}');
            }
        });
    });
}

From source file:vk.model.VKPrivacy.java

/**
 * Parses privacy in int format from privacy_view format.
 * @see <a href="http://vk.com/dev/privacy_setting">http://vk.com/dev/privacy_setting</a>
 *//*from   w  ww . j a  va  2  s .co  m*/
public static int parsePrivacy(JsonNode privacyView) {
    int privacy = 0;
    if (privacyView != null) {
        String type = privacyView.get("type").asText();
        if ("all".equals(type)) {
            privacy = PRIVACY_ALL;
        } else if ("friends".equals(type)) {
            privacy = PRIVACY_FRIENDS;
        } else if ("friends_of_friends".equals(type)) {
            privacy = PRIVACY_FRIENDS_OF_FRIENDS;
        } else if ("nobody".equals(type)) {
            privacy = PRIVACY_NOBODY;
        } else {
            privacy = PRIVACY_UNKNOWN;
        }
    }
    return privacy;
}

From source file:com.baasbox.commands.CollectionsResource.java

private static String extractCollectionName(JsonNode command) throws CommandParsingException {
    JsonNode node = command.get(ScriptCommand.PARAMS);
    if (!node.isTextual()) {
        throw new CommandParsingException(command, "expeceted params to be the name of a collection");
    }/*from  ww w.j a va2  s. c  om*/
    return node.asText();
}

From source file:com.arpnetworking.tsdcore.sinks.ReMetSinkTest.java

private static void assertJsonEqualsDatum(final JsonNode jsonNode, final AggregatedData datum) {
    Assert.assertEquals(datum.getValue().getValue(), jsonNode.get("value").asDouble(), 0.001);
    Assert.assertEquals(datum.getFQDSN().getMetric(), jsonNode.get("metric").asText());
    Assert.assertEquals(datum.getFQDSN().getService(), jsonNode.get("service").asText());
    Assert.assertEquals(datum.getHost(), jsonNode.get("host").asText());
    Assert.assertEquals(datum.getPeriod(), Period.parse(jsonNode.get("period").asText()));
    Assert.assertEquals(datum.getPeriodStart().getMillis(),
            DateTime.parse(jsonNode.get("periodStart").asText()).getMillis());
    Assert.assertEquals(datum.getFQDSN().getStatistic().getName(), jsonNode.get("statistic").asText());
}

From source file:monasca.api.resource.exception.ErrorMessages.java

public static ErrorMessageMatcher assertThat(final String errorMessage) {
    try {/* w ww .  j  av a  2s .  c om*/
        JsonNode node = MAPPER.readTree(errorMessage);
        final String rootKey = node.fieldNames().next();
        node = node.get(rootKey);
        final ErrorMessage message = MAPPER.reader(ErrorMessage.class).readValue(node);

        return new ErrorMessageMatcher() {
            @Override
            public void matches(String faultType, int code, String messagePrefix) {
                matches(faultType, code, messagePrefix, null);
            }

            @Override
            public void matches(String faultType, int code, String messagePrefix,
                    @Nullable String detailsPrefix) {
                assertEquals(rootKey, faultType);
                assertEquals(message.code, code);
                assertTrue(message.message.startsWith(messagePrefix),
                        String.format("String '%s' does not start with '%s'", message.message, messagePrefix));
                if (detailsPrefix != null)
                    assertTrue(message.details.startsWith(detailsPrefix), message.details);
            }
        };

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:monasca.log.api.resource.exception.ErrorMessages.java

public static ErrorMessageMatcher assertThat(final String errorMessage) {
    try {/*from  w  ww  . j  av  a2 s .c o m*/
        JsonNode node = MAPPER.readTree(errorMessage);
        final String rootKey = node.fieldNames().next();
        node = node.get(rootKey);
        final ErrorMessage message = MAPPER.reader(ErrorMessage.class).readValue(node);

        return new ErrorMessageMatcher() {
            @Override
            public void matches(String faultType, int code, String messagePrefix) {
                matches(faultType, code, messagePrefix, null);
            }

            @Override
            public void matches(String faultType, int code, String messagePrefix,
                    @Nullable String detailsPrefix) {
                assertEquals(rootKey, faultType);
                assertEquals(message.code, code);
                assertTrue(message.message.startsWith(messagePrefix), message.message);
                if (detailsPrefix != null)
                    assertTrue(message.details.startsWith(detailsPrefix), message.details);
            }
        };

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.flipkart.zjsonpatch.JsonPatch.java

private static JsonNode getPatchAttrWithDefault(JsonNode jsonNode, String attr, JsonNode defaultValue) {
    JsonNode child = jsonNode.get(attr);
    if (child == null)
        return defaultValue;
    else/*from w w  w.j av a  2s  .c  om*/
        return child;
}

From source file:org.jboss.aerogear.sync.client.netty.SyncClientHandler.java

private static void unknownMessageType(final ChannelHandlerContext ctx, final JsonNode json) {
    ctx.channel().writeAndFlush(/*ww  w.j a v  a2s .  co  m*/
            textFrame("{\"result\": \"Unknown msgType '" + json.get("msgType").asText() + "'\"}"));
}