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.nirmata.workflow.details.JsonSerializer.java

public static StartedTask getStartedTask(JsonNode node) {
    return new StartedTask(node.get("instanceName").asText(),
            LocalDateTime.parse(node.get("startDateUtc").asText(), DateTimeFormatter.ISO_DATE_TIME));
}

From source file:com.pkrete.locationservice.admin.util.LocationJSONDeserializerHelper.java

/**
 * Deserializes areas variable.//from w ww .j  a  v  a  2  s.c  o m
 *
 * @param location Location object
 * @param node JSON node that contains the data
 */
public static void deserializeAreas(Location location, JsonNode node) {
    List<Area> areas = new ArrayList<Area>();

    // Does areas node exist
    if (node.path("areas") != null) {
        // Parse areas
        Iterator<JsonNode> ite = node.path("areas").elements();
        // Iterate notes
        while (ite.hasNext()) {
            // Get next area
            JsonNode temp = ite.next();
            // Parse id
            int areaId = temp.get("id") == null ? 0 : temp.get("id").intValue();
            // Parse x1
            int x1 = temp.get("x1") == null ? 0 : temp.get("x1").intValue();
            // Parse y1
            int y1 = temp.get("y1") == null ? 0 : temp.get("y1").intValue();
            // Parse x2
            int x2 = temp.get("x2") == null ? 0 : temp.get("x2").intValue();
            // Parse y2
            int y2 = temp.get("y2") == null ? 0 : temp.get("y2").intValue();
            // Parse angle
            int angle = temp.get("angle") == null ? 0 : temp.get("angle").intValue();

            areas.add(new Area(areaId, x1, y1, x2, y2, angle, location));
        }
    }
    // Set areas
    location.setAreas(areas);
}

From source file:io.orchestrate.client.ResponseConverterUtil.java

public static <T> Event<T> wrapperJsonToEvent(ObjectMapper mapper, JsonNode wrapperJson, Class<T> clazz)
        throws IOException {
    assert (mapper != null);
    assert (clazz != null);

    final JsonNode path = wrapperJson.get("path");

    final String collection = path.get("collection").textValue();
    final String key = path.get("key").textValue();
    final String eventType = path.get("type").textValue();
    final String ref = path.get("ref").textValue();

    final long timestamp = path.get("timestamp").longValue();
    final String ordinal = path.get("ordinal").asText();

    final JsonNode valueNode = wrapperJson.get("value");

    final T value = jsonToDomainObject(mapper, valueNode, clazz);
    String rawValue = null;// www.j a  v  a2  s.c  o m
    if (value != null && value instanceof String) {
        rawValue = (String) value;
    }

    return new Event<T>(mapper, collection, key, eventType, timestamp, ordinal, ref, value, valueNode,
            rawValue);
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static TaskExecutionResult getTaskExecutionResult(JsonNode node) {
    JsonNode subTaskRunIdNode = node.get("subTaskRunId");
    return new TaskExecutionResult(TaskExecutionStatus.valueOf(node.get("status").asText().toUpperCase()),
            node.get("message").asText(), getMap(node.get("resultData")),
            ((subTaskRunIdNode != null) && !subTaskRunIdNode.isNull()) ? new RunId(subTaskRunIdNode.asText())
                    : null,/*from  ww  w  .java2s  . c  o  m*/
            LocalDateTime.parse(node.get("completionTimeUtc").asText(), DateTimeFormatter.ISO_DATE_TIME));
}

From source file:com.pros.jsontransform.filter.ArrayFilterContains.java

public static boolean evaluate(final JsonNode filterNode, final JsonNode elementNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    // contains only supports string type
    String fieldValue, likeValue;
    boolean result = false;
    JsonNode filterArguments = filterNode.get(ArrayFilter.$CONTAINS.name().toLowerCase());
    if (elementNode.isObject()) {
        // compare objects
        fieldValue = transformer.transformValueNode(elementNode, filterArguments).asText();
    } else {/*from  w  ww  .  j a va2  s .c  o m*/
        // compare values
        fieldValue = elementNode.asText();
    }
    likeValue = filterArguments.path(ArrayFilter.ARGUMENT_WHAT).asText();
    if (fieldValue.contains(likeValue)) {
        result = true;
    }
    return result;
}

From source file:com.spotify.helios.Utils.java

private static String imageInfo(final String path) {
    final JsonNode node;
    try {//from w ww . j  av a  2 s  .c o m
        final String json = new String(Files.readAllBytes(Paths.get(path)));
        node = Json.readTree(json);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    final JsonNode imageNode = node.get("image");
    return (imageNode == null || imageNode.getNodeType() != STRING) ? null : imageNode.asText();
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java

public static boolean hasLine(String line, Context context) {
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("timetable");
    String[] sublines = line.split(",");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        for (int j = 0; j < sublines.length; j++) {
            if (lineJson.get("line").asText().equalsIgnoreCase(sublines[j].trim())) {
                return true;
            }//from   www .  j av  a2 s.com
        }
    }
    return false;
}

From source file:org.bndtools.rt.repository.marshall.CapReqJson.java

private static JsonNode getRequiredField(JsonNode node, String fieldName) throws IllegalArgumentException {
    JsonNode child = node.get(fieldName);
    if (child == null)
        throw new IllegalArgumentException(String.format("Missing required field '%s'", fieldName));
    return child;
}

From source file:models.Friend.java

public static List<Friend> all() {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);//from   ww w  . j a  va2 s  . c o  m

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.getAllFriends(userID);
    Iterator<JsonNode> it = allfriends.get("friends").iterator();

    List<Friend> friends = new ArrayList<Friend>();
    while (it.hasNext()) {
        JsonNode now = it.next();
        friends.add(new Friend(now.get("userName").asText(), now.get("userId").asInt()));
    }
    /*
    JsonNode postsNode = APICall
        .callAPI(GET_POSTS_CALL);
            
    if (postsNode == null || postsNode.has("error")
        || !postsNode.isArray()) {
    return posts;
    }
            
    for (int i = 0; i < postsNode.size(); i++) {
    JsonNode json = postsNode.path(i);
    Post post = new Post(json.path("image").asText(),json.path("text").asText(),json.path("title").asText());
    posts.add(post);
    }
    */
    return friends;
}

From source file:models.Friend.java

public static List<Friend> allSubscribe() {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);/*from www .j av a  2 s.  c  om*/

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.getAllFriends(userID);
    Iterator<JsonNode> it = allfriends.get("subscribeUsers").iterator();

    List<Friend> friends = new ArrayList<Friend>();
    while (it.hasNext()) {
        JsonNode now = it.next();
        friends.add(new Friend(now.get("userName").asText(), now.get("userId").asInt()));
    }
    /*
    JsonNode postsNode = APICall
        .callAPI(GET_POSTS_CALL);
            
    if (postsNode == null || postsNode.has("error")
        || !postsNode.isArray()) {
    return posts;
    }
            
    for (int i = 0; i < postsNode.size(); i++) {
    JsonNode json = postsNode.path(i);
    Post post = new Post(json.path("image").asText(),json.path("text").asText(),json.path("title").asText());
    posts.add(post);
    }
    */
    return friends;
}