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:com.squarespace.template.plugins.platform.CommerceUtils.java

public static boolean hasVariedPrices(JsonNode item) {
    ProductType type = getProductType(item);
    JsonNode structuredContent = item.path("structuredContent");

    switch (type) {
    case PHYSICAL:
    case SERVICE:
    case GIFT_CARD:
        JsonNode variants = structuredContent.path("variants");
        JsonNode first = variants.get(0);
        for (int i = 1; i < variants.size(); i++) {
            JsonNode var = variants.get(i);
            boolean flag1 = !var.path("onSale").equals(first.path("onSale"));
            boolean flag2 = isTruthy(first.path("onSale"))
                    && !var.path("salePrice").equals(first.path("salePrice"));
            boolean flag3 = !var.path("price").equals(first.path("price"));
            if (flag1 || flag2 || flag3) {
                return true;
            }//ww  w .j  a v  a2  s.c  o m
        }
        return false;
    case DIGITAL:
    default:
        return false;
    }
}

From source file:services.TodoService.java

public static Todo edit(String accessToken, Long id, String description) {
    WSRequestHolder req = WS.url(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/edit");
    req.setHeader("Authorization", "Bearer " + accessToken);

    JsonNode json = Json.newObject().put("id", id).put("description", description);

    Promise<Todo> jsonPromise = req.post(json).map(new Function<WSResponse, Todo>() {
        public Todo apply(WSResponse response) {
            JsonNode json = response.asJson();
            Todo todo = new Todo();
            todo.setId(json.get("id").asLong());
            todo.setDescription(json.get("description").asText());
            todo.setUsername(json.get("username").asText());
            return todo;
        }/*from w  w w.j  av a  2s .c  o m*/
    });

    return jsonPromise.get(5000);
}

From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java

public static void deserialize(AbstractAwsIotDevice device, String jsonState) throws IOException {
    ObjectMapper jsonObjectMapper = device.getJsonObjectMapper();

    JsonNode node = jsonObjectMapper.readTree(jsonState);
    if (node == null) {
        throw new IOException("Invalid delta update received for " + device.getThingName());
    }/*from   w w  w. j a v a2  s. c o  m*/

    for (Iterator<String> it = node.fieldNames(); it.hasNext();) {
        String property = it.next();
        Field field = device.getUpdatableProperties().get(property);
        JsonNode fieldNode = node.get(property);
        if (field == null || fieldNode == null) {
            continue;
        }

        updateDeviceProperty(jsonObjectMapper, fieldNode, device, field);
    }
}

From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java

/**
 * Query the parent node for the named child node.
 *
 * @param parentNode Node to check./*from w ww . j ava  2s.co m*/
 * @param name Name of child node.
 * @return The child node if found.
 * @throws NoFieldException Thrown if field not found.
 */
public static JsonNode getExpectedNode(JsonNode parentNode, String name) throws NoFieldException {
    JsonNode childNode = parentNode.get(name);
    if (null == childNode) {
        throw new NoFieldException(name);
    }
    return childNode;
}

From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java

/**
 * Query the parent node for the named child node and return the text value of the child node
 *
 * @param parentNode Node to check./*from w w w .  java 2s .  c o m*/
 * @param name Name of the child node.
 * @return The text value of the child node.
 * @throws NoFieldException Thrown if field not found.
 */
public static String getExpectedStringValue(JsonNode parentNode, String name) throws NoFieldException {
    JsonNode childNode = parentNode.get(name);
    if (null == childNode) {
        throw new NoFieldException(name);
    }
    return childNode.textValue();
}

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

private static Integer removeRemaining(List<Diff> diffs, List<Object> path, int pos, int srcIdx, int srcSize,
        JsonNode source) {

    while (srcIdx < srcSize) {
        List<Object> currPath = getPath(path, pos);
        diffs.add(Diff.generateDiff(Operation.REMOVE, currPath, source.get(srcIdx)));
        srcIdx++;//from w ww  .  java 2  s.  c  o m
    }
    return pos;
}

From source file:dk.kk.ibikecphlib.util.HttpUtils.java

public static Message JSONtoUserDataMessage(JsonNode result, UserData userData) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        if (result.has("invalid_token")) {
            if (result.get("invalid_token").asBoolean()) {
                data.putBoolean("invalid_token", result.get("invalid_token").asBoolean());
                IBikeApplication.logoutWrongToken();
            }/*from   ww w .j a  v  a 2 s. co  m*/
        }
        if (result != null && result.has("data")) {
            JsonNode dataNode = result.get("data");
            if (dataNode != null) {
                data.putInt("id", dataNode.get("id").asInt());
                data.putString("name", dataNode.get("name").asText());
                data.putString("email", dataNode.get("email").asText());
                if (dataNode.has("image_url"))
                    data.putString("image_url", dataNode.get("image_url").asText());
            }
        }
        ret.setData(data);
    }
    return ret;
}

From source file:io.syndesis.dao.DeploymentDescriptorTest.java

private static void assertActionProperties(final String connectorId, final JsonNode action,
        final String actionName, final JsonNode catalogedJsonSchema) {
    final JsonNode actionDefinition = action.get("definition");

    final JsonNode propertiesFromCatalog = catalogedJsonSchema.get("properties");

    // make sure that all action properties are as defined in
    // the connector
    StreamSupport.stream(actionDefinition.get("propertyDefinitionSteps").spliterator(), true)
            .flatMap(step -> StreamSupport.stream(Spliterators
                    .spliteratorUnknownSize(step.get("properties").fields(), Spliterator.CONCURRENT), true))
            .forEach(property -> {//from   w w w .j  av a2  s.  c o  m
                final String propertyName = property.getKey();
                final JsonNode propertyDefinition = property.getValue();

                final JsonNode catalogedPropertyDefinition = propertiesFromCatalog.get(propertyName);

                assertThat(catalogedPropertyDefinition).as(
                        "Definition of `%s` connector's action `%s` defines a property `%s` that is not defined in the Camel connector",
                        connectorId, actionName, propertyName).isNotNull();

                assertThat(propertyDefinition.get("componentProperty"))
                        .as("`componentProperty` field is missing for connector's %s %s action property %s",
                                connectorId, actionName, propertyName)
                        .isNotNull();
                assertThat(propertyDefinition.get("componentProperty").asBoolean()).as(
                        "Definition of `%s` connector's action `%s` property `%s` should be marked as `componentProperty`",
                        connectorId, actionName, propertyName).isFalse();
                // remove Syndesis specifics
                final ObjectNode propertyDefinitionForComparisson = propertyNodeForComparisson(
                        propertyDefinition);

                // remove properties that we would like to customize
                removeCustomizedProperties(propertyDefinitionForComparisson, catalogedPropertyDefinition);

                assertThat(propertyDefinitionForComparisson).as(
                        "Definition of `%s` connector's action's `%s` property `%s` differs from the one in Camel connector",
                        connectorId, actionName, propertyName).isEqualTo(catalogedPropertyDefinition);
            });
}

From source file:models.service.IPBasedLocationService.java

/**
 * ?????/*from   w ww  .j  a  v  a 2s .c o  m*/
 * 
 * @param ip ip?
 * @return ??,null - ???
 */
public static String getSimpleAddress(String ip) {
    Promise<Response> get = WSUtil.get(baiduServiceURL, "ak", baiduServiceAK, "ip", ip);

    Response response;
    try {
        response = get.get(REQUEST_TIMEOUT);
    } catch (RuntimeException e) {
        LOGGER.error("IP?API", e);
        return null;
    }

    String body = response.getBody();
    JsonNode locationJsonNode = null;

    try {
        body = StringEscapeUtils.unescapeJava(body);
        locationJsonNode = Json.parse(body);
    } catch (RuntimeException e) {
        LOGGER.error("IP?APIJSON?JSON" + body, e);
        return null;
    }

    String simpleAddress = null;

    if (locationJsonNode.has("content") && locationJsonNode.get("content").has("address")) {
        simpleAddress = locationJsonNode.get("content").get("address").asText();
    } else {
        LOGGER.error("IP?API?JSON" + body);
    }

    return simpleAddress;
}

From source file:de.unikonstanz.winter.crossref.node.doi.CrossrefDoiNodeModel.java

private static DataCell partialDateNodeToIntListCell(final JsonNode node) {
    if (CrossrefUtil.isNull(node)) {
        return new MissingCell(null);
    }/*from   w  w w. ja v a  2  s.c o m*/
    JsonNode dateParts = node.get("date-parts");
    if (CrossrefUtil.isNull(dateParts)) {
        return new MissingCell(null);
    }
    return CrossrefUtil.nodeToIntListCell(dateParts.iterator().next());
}