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.pac4j.oauth.profile.JsonHelper.java

/**
 * Return the field with name in JSON (a string, a boolean, a number or a node).
 *
 * @param json json//from   w  ww  .ja va  2 s.  c o  m
 * @param name node name
 * @return the field
 */
public static Object get(final JsonNode json, final String name) {
    if (json != null && name != null) {
        JsonNode node = json;
        for (String nodeName : name.split("\\.")) {
            if (node != null) {
                node = node.get(nodeName);
            }
        }
        if (node != null) {
            if (node.isNumber()) {
                return node.numberValue();
            } else if (node.isBoolean()) {
                return node.booleanValue();
            } else if (node.isTextual()) {
                return node.textValue();
            } else {
                return node;
            }
        }
    }
    return null;
}

From source file:com.ikanow.aleph2.data_import_manager.harvest.modules.LocalHarvestTestModule.java

private static JsonNode safeJsonGet(String fieldname, JsonNode src) {
    final JsonNode j = Optional.ofNullable(src.get(fieldname)).orElse(JsonNodeFactory.instance.objectNode());
    //DEBUG//from   w  ww  . j  a  v a 2  s  .  com
    //System.out.println(j);
    return j;
}

From source file:org.apache.drill.exec.store.http.util.JsonConverter.java

public static JsonNode parse(String content, String key) {
    String[] path = key.split("/");
    try {//w ww.j  a  v  a  2  s.  c  om
        JsonNode node = from(content);
        for (String p : path) {
            if (node == null) {
                return null;
            }
            node = node.get(p);
        }
        return node;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:nextflow.fs.dx.api.DxEnv.java

private static String getTextValue(JsonNode jsonNode, String key) {
    JsonNode value = jsonNode.get(key);
    if (value == null) {
        return null;
    }//w  w  w.j a  v  a 2  s. com
    return value.asText();
}

From source file:com.galenframework.ide.devices.tasks.DeviceTaskParser.java

private static DeviceCommand parseCommand(ObjectMapper mapper, JsonNode commandNode)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {/*from w  w w .j a  v  a2  s .  c  o m*/
    String commandName = commandNode.get("name").asText();
    if (commandClasses.containsKey(commandName)) {
        Class<? extends DeviceCommand> commandClass = commandClasses.get(commandName);
        if (commandNode.has("parameters")) {
            return mapper.convertValue(commandNode.get("parameters"), commandClasses.get(commandName));
        } else {
            return commandClass.getConstructor().newInstance();
        }

    } else {
        throw new RuntimeException("Unknown command type: " + commandName);
    }
}

From source file:com.reprezen.swagedit.json.references.JsonReference.java

public static JsonPointer getPointer(JsonNode node) {
    JsonNode value = node.get(PROPERTY);

    if (value != null) {
        return createPointer(value.asText());
    } else {/*from   www.j a va 2  s . c  o  m*/
        return createPointer(null);
    }
}

From source file:org.jboss.aerogear.simplepush.server.netty.standalone.ConfigReader.java

private static DataStore createDataStore(final JsonNode json) {
    final JsonNode dataStore = json.get("datastore");
    if (dataStore == null) {
        throw new IllegalArgumentException("datastore element must be specified");
    }/*from w  ww.  j  a va 2s  . co m*/
    final JsonNode inMemory = dataStore.get("in-memory");
    if (inMemory != null) {
        return new InMemoryDataStore();
    }
    final JsonNode redis = dataStore.get("redis");
    if (redis != null) {
        return new RedisDataStore(redis.get("host").asText(), redis.get("port").asInt());
    }
    final JsonNode couchdb = dataStore.get("couchdb");
    if (couchdb != null) {
        return new CouchDBDataStore(couchdb.get("url").asText(), couchdb.get("dbName").asText());
    }
    final JsonNode jpa = dataStore.get("jpa");
    if (jpa != null) {
        return new JpaDataStore(jpa.get("persistenceUnit").asText());
    }
    throw new IllegalStateException("datastore must be specified");
}

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

private static JsonNode log(JsonNode command, JsonCallback callback) throws CommandException {
    JsonNode idOfTheModule = command.get(ScriptCommand.MAIN);
    JsonNode par = command.get(ScriptCommand.PARAMS);
    if (idOfTheModule == null) {
        idOfTheModule = command.get(ScriptCommand.ID);
    }//from   w  w  w. j a v a  2  s. c o m
    ObjectNode message = Json.mapper().createObjectNode();
    message.put("message", par.get("message"));
    message.put("args", par.get("args"));
    message.put("script", idOfTheModule);
    message.put("date", SDF.format(new Date()));
    int publish = EventsService.publish(EventsService.StatType.SCRIPT, message);
    return IntNode.valueOf(publish);
}

From source file:org.fcrepo.importexport.common.BagProfile.java

private static Set<String> arrayValues(final JsonNode json, final String key) {
    final JsonNode values = json.get(key);

    if (values == null) {
        return null;
    }/*from  w w w . ja va2s .c om*/

    final Set<String> results = new HashSet<>();
    for (int i = 0; i < values.size(); i++) {
        results.add(values.get(i).asText());
    }
    return results;
}

From source file:org.xbmc.kore.utils.JsonUtils.java

public static List<String> stringListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<String>(0);
    JsonNode value = node.get(key);
    if (value == null)
        return new ArrayList<String>(0);

    ArrayList<String> result;
    if (value.isArray()) {
        ArrayNode arrayNode = (ArrayNode) value;
        result = new ArrayList<String>(arrayNode.size());
        for (JsonNode innerNode : arrayNode) {
            result.add(innerNode.textValue());
        }/*from  w ww.j  ava 2  s .  c o m*/
    } else {
        // This isn't exactly what we're expecting, but we can return the text value
        result = new ArrayList<String>(1);
        result.add(value.textValue());
    }
    return result;
}