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:volker.streaming.music.lastfm.LastFmTrackFactory.java

/**
 * Parse a Track from a given JsonNode.//w  ww. j a  va  2  s. c om
 * 
 * @param jsonTrack the JSON representation of the Track.
 * @return the Track.
 * @throws IllegalArgumentException if the jsonTrack is not valid (see {@link #isValid(JsonNode)}).
 */
public static Track fromJson(JsonNode jsonTrack) {
    if (!isValid(jsonTrack)) {
        throw new IllegalArgumentException("Invalid json track format.");
    }
    Track track = new Track();
    track.setArtist(getTextItem(jsonTrack, ARTIST));
    track.setName(jsonTrack.get(NAME).asText());
    track.setAlbum(getTextItem(jsonTrack, ALBUM));
    return track;
}

From source file:org.jsonschema2pojo.integration.MediaIT.java

public static void roundTripAssertions(ObjectMapper objectMapper, String propertyName, String jsonValue,
        Object javaValue) throws Exception {

    ObjectNode node = objectMapper.createObjectNode();
    node.put(propertyName, jsonValue);//from   w  ww.  ja  v a 2s . c o  m

    Object pojo = objectMapper.treeToValue(node, classWithMediaProperties);

    Method getter = new PropertyDescriptor(propertyName, classWithMediaProperties).getReadMethod();

    assertThat(getter.invoke(pojo), is(equalTo(javaValue)));

    JsonNode jsonVersion = objectMapper.valueToTree(pojo);

    assertThat(jsonVersion.get(propertyName).asText(), is(equalTo(jsonValue)));
}

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

@SuppressWarnings("unchecked")
static <T> KvObject<T> jsonToKvObject(final ObjectMapper objectMapper, final JsonNode jsonNode,
        final Class<T> clazz) throws IOException {
    // parse the PATH structure (e.g.):
    // {"collection":"coll","key":"aKey","ref":"someRef"}
    final JsonNode path = jsonNode.get("path");
    final String collection = path.get("collection").asText();
    final String key = path.get("key").asText();
    final String ref = path.get("ref").asText();
    final KvMetadata metadata = new KvMetadata(collection, key, ref);

    // parse result structure (e.g.):
    // {"path":{...},"value":{}}
    final JsonNode valueNode = jsonNode.get("value");
    final String rawValue = valueNode.toString();

    final T value;
    if (clazz == String.class) {
        // don't deserialize JSON data
        value = (T) rawValue;/*from w w w . j  a v  a 2 s .c o m*/
    } else {
        value = objectMapper.readValue(rawValue, clazz);
    }

    return new KvObject<T>(metadata, value, rawValue);
}

From source file:org.glowroot.tests.WebDriverIT.java

private static void deleteAllInstrumentation() throws Exception {
    String content = httpGet(//from   ww  w.  j  a  va 2s .co m
            "http://localhost:" + getUiPort() + "/backend/config/instrumentation?agent-id=" + agentId);
    ArrayNode instrumentations = (ArrayNode) new ObjectMapper().readTree(content).get("configs");
    for (JsonNode instrumentation : instrumentations) {
        String version = instrumentation.get("version").asText();
        httpPost("http://localhost:" + getUiPort() + "/backend/config/instrumentation/remove?agent-id="
                + agentId, "{\"versions\":[\"" + version + "\"]}");
    }
}

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

public static Task getTask(JsonNode node) {
    Map<TaskId, WorkTask> workMap = Maps.newHashMap();
    node.get("tasks").forEach(n -> {
        WorkTask workTask = new WorkTask();
        JsonNode taskTypeNode = n.get("taskType");
        workTask.taskId = new TaskId(n.get("taskId").asText());
        workTask.taskType = ((taskTypeNode != null) && !taskTypeNode.isNull()) ? getTaskType(taskTypeNode)
                : null;//from w  ww. j  av  a2 s. c o  m
        workTask.metaData = getMap(n.get("metaData"));
        workTask.childrenTaskIds = Lists.newArrayList();
        n.get("childrenTaskIds").forEach(c -> workTask.childrenTaskIds.add(c.asText()));

        workMap.put(workTask.taskId, workTask);
    });
    String rootTaskId = node.get("rootTaskId").asText();
    return buildTask(workMap, Maps.newHashMap(), rootTaskId);
}

From source file:org.opendaylight.ovsdb.lib.schema.ColumnSchema.java

public static ColumnSchema fromJson(String name, JsonNode json) {
    if (!json.isObject() || !json.has("type")) {
        throw new BadSchemaException("bad column schema root, expected \"type\" as child");
    }/*from w  w w.j  a  v a2s.c om*/

    return new ColumnSchema(name, ColumnType.fromJson(json.get("type")));
}

From source file:com.github.fge.jsonschema.tree.BaseSchemaTree.java

/**
 * Build a JSON Reference from a node//from w w w . j  a  v  a  2  s.  co  m
 *
 * <p>This will return {@code null} if the reference could not be built. The
 * conditions for a successful build are as follows:</p>
 *
 * <ul>
 *     <li>the node is an object;</li>
 *     <li>it has a member named {@code id};</li>
 *     <li>the value of this member is a string;</li>
 *     <li>this string is a valid URI.</li>
 * </ul>
 *
 * @param node the node
 * @return a JSON Reference, or {@code null}
 */
protected static JsonRef idFromNode(final JsonNode node) {
    if (!node.path("id").isTextual())
        return null;

    try {
        return JsonRef.fromString(node.get("id").textValue());
    } catch (JsonReferenceException ignored) {
        return null;
    }
}

From source file:com.meetingninja.csse.database.TaskDatabaseAdapter.java

public static Task parseTasks(JsonNode node) {
    Task t = new Task(); // start parsing a task
    if (node.hasNonNull(Keys._ID)) {
        String id = node.get(Keys._ID).asText();
        t.setID(id);//  w w w . j  a  v  a 2  s  .c om
        t.setTitle(JsonUtils.getJSONValue(node, Keys.Task.TITLE));
        t.setType(JsonUtils.getJSONValue(node, Keys.TYPE));
    } else {
        Log.w(TAG, "Parsed null task");
        return null;
    }
    return t;

}

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

public static RunnableTask getRunnableTask(JsonNode node) {
    List<RunnableTaskDag> taskDags = Lists.newArrayList();
    node.get("taskDags").forEach(n -> taskDags.add(getRunnableTaskDag(n)));

    Map<TaskId, ExecutableTask> tasks = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> fields = node.get("tasks").fields();
    while (fields.hasNext()) {
        Map.Entry<String, JsonNode> next = fields.next();
        tasks.put(new TaskId(next.getKey()), getExecutableTask(next.getValue()));
    }// w w  w.  j a  v  a2 s . co m

    LocalDateTime startTime = LocalDateTime.parse(node.get("startTimeUtc").asText(),
            DateTimeFormatter.ISO_DATE_TIME);
    LocalDateTime completionTime = node.get("completionTimeUtc").isNull() ? null
            : LocalDateTime.parse(node.get("completionTimeUtc").asText(), DateTimeFormatter.ISO_DATE_TIME);
    RunId parentRunId = node.get("parentRunId").isNull() ? null : new RunId(node.get("parentRunId").asText());
    return new RunnableTask(tasks, taskDags, startTime, completionTime, parentRunId);
}

From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java

@SuppressWarnings("unchecked")
public static List<List<?>> getValues(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper)
        throws IOException {
    List<List<?>> values = null;
    List<String> classes = null;
    if (n.has("types"))
        classes = mapper.readValue(n.get("types").asText(), List.class);
    if (n.has("values")) {
        JsonNode nn = n.get("values");
        values = new ArrayList<List<?>>();
        if (nn.isArray()) {
            for (JsonNode nno : nn) {
                if (nno.isArray()) {
                    ArrayList<Object> val = new ArrayList<Object>();
                    for (int i = 0; i < nno.size(); i++) {
                        JsonNode nnoo = nno.get(i);
                        Object obj = parent.deserialize(nnoo, mapper);
                        val.add(TableDisplayDeSerializer.getValueForDeserializer(obj,
                                classes != null && classes.size() > i ? classes.get(i) : null));
                    }/*w  ww  . j  a  v  a2 s .c  om*/
                    values.add(val);
                }
            }
        }
    }
    return values;
}