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:models.NasaRegistration.java

public static String getUserInfo(String userName, String password) {

    List<NasaRegistration> allUsers = new ArrayList<NasaRegistration>();
    String GET_IND_USER_DATA = "http://einstein.sv.cmu.edu:9000/getContestUser/";
    GET_IND_USER_DATA = GET_IND_USER_DATA + userName + '/' + password + '/' + "json";
    // Call the API to get the json string
    JsonNode usersNode = APICall.callAPI(GET_IND_USER_DATA);

    System.out.println("Output1:" + GET_IND_USER_DATA);
    System.out.println("Check:" + usersNode.toString());
    // if no value is returned or error or is not json array
    if (usersNode == null || usersNode.has("error")) {
        System.out.println("inside userNode check");
        return null;
    }/*w ww  .  j  av  a  2s .co  m*/
    System.out.println("userName response:" + usersNode.get("userName"));
    System.out.println("userName:" + userName);
    System.out.println("password:" + usersNode.get("password"));

    if (usersNode.get("userName").textValue().equals(userName)
            && usersNode.get("password").textValue().equals(password)) {
        System.out.println("Comes inside the if block");
        return usersNode.get("firstName").textValue();
    } else {
        System.out.println("Does not come inside the if clause");
        return null;
    }
}

From source file:com.vmware.admiral.closures.util.ClosureUtils.java

public static JsonElement toJsonElement(JsonNode node) {
    JsonObject jsObject = new JsonObject();

    Iterator<String> fieldsIterator = node.fieldNames();
    if (!fieldsIterator.hasNext()) {
        if (node.isObject()) {
            return jsObject;
        }/*from   ww w .j  ava  2s.c  om*/
        return getPrimitiveJsonElement(node);
    }

    while (fieldsIterator.hasNext()) {
        String field = fieldsIterator.next();
        JsonNode childNode = node.get(field);
        JsonElement convertedValue = getJsonObjElement(childNode);
        jsObject.add(field, convertedValue);
    }

    return jsObject;
}

From source file:controllers.user.UserSettingApp.java

/**
 * ?//from   w ww  .  j  a  v a 2  s  .  com
 * 
 * @return
 */
@Transactional
public static Result completeUserInfo() {
    JsonNode json = getJson();

    if (!json.hasNonNull("email") || !json.hasNonNull("pwd")) {
        return illegalParameters();
    }

    String email = json.get("email").asText();
    String pwd = json.get("pwd").asText();

    ObjectNodeResult result = User.completeUserInfo(session(), email, pwd);

    return ok(result.getObjectNode());
}

From source file:com.ikanow.aleph2.management_db.mongodb.services.IkanowV1SyncService_Buckets.java

/** Gets a JSON field that may not be present (justs an empty JsonNode if no)
 * @param fieldname// www.  j av a2  s  .c  o m
 * @param src
 * @return
 */
protected static JsonNode safeJsonGet(String fieldname, JsonNode src) {
    final JsonNode j = Optional.ofNullable(src.get(fieldname)).orElse(JsonNodeFactory.instance.objectNode());
    //DEBUG
    //System.out.println(j);
    return j;
}

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

public static List<Group> getGroups(String userID) throws IOException {
    // Server URL setup
    System.out.println(userID);/*from w w  w.  j  a  va2  s .c  o m*/
    String _url = getBaseUri().appendPath("Groups").appendPath(userID).build().toString();
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    // add request header
    conn.setRequestMethod(IRequest.GET);
    addRequestHeader(conn, false);

    // Get server response
    int responseCode = conn.getResponseCode();
    String response = getServerResponse(conn);

    System.out.println("yes");

    // Initialize ObjectMapper
    List<Group> groupList = new ArrayList<Group>();
    List<String> groupIDList = new ArrayList<String>();
    System.out.println("maybe");
    final JsonNode groupArray = MAPPER.readTree(response).get(Keys.Group.LIST);
    System.out.println("no");

    if (groupArray.isArray()) {
        for (final JsonNode groupNode : groupArray) {
            String _id = groupNode.get(Keys.Group.ID).asText();
            System.out.println(_id);
            groupIDList.add(_id);
        }
    }
    conn.disconnect();

    for (String id : groupIDList) {
        groupList.add(GroupDatabaseAdapter.getGroup(id));
    }

    return groupList;
}

From source file:com.ikanow.aleph2.logging.utils.Log4JUtils.java

public static String getLog4JMessage(final JsonNode logObject, final Level level, final StackTraceElement stack,
        final String date_field, final Map<String, Object> map, final String hostname) {
    StringBuilder sb = new StringBuilder();
    final String c = stack.getClassName().substring(stack.getClassName().lastIndexOf(".") + 1);
    final String l = Integer.toString(stack.getLineNumber());
    final String thread = Thread.currentThread().getName().isEmpty()
            ? Long.toString(Thread.currentThread().getId())
            : Thread.currentThread().getName();
    sb.append(String.format(message_format, date_format.format(new Date(logObject.get(date_field).asLong())),
            thread, level.name(), c, l, logObject.get("message").asText()));
    sb.append(String.format(field_format, "bucket", logObject.get("bucket").asText()));
    sb.append(String.format(field_format, "hostname", hostname));
    sb.append(String.format(field_format, "subsystem", logObject.get("subsystem").asText()));
    sb.append(String.format(field_format, "command", logObject.get("command").asText()));
    Optional.ofNullable(map).orElse(Collections.emptyMap()).entrySet().stream()
            .forEach(e -> sb.append(String.format(field_format, e.getKey(), e.getValue())));
    return sb.toString();
}

From source file:controllers.Features.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> create() {
    final JsonNode json = request().body().asJson();
    ObjectNode props = (ObjectNode) json.deepCopy();
    props.remove("targets");
    Promise<Boolean> created = Feature.nodes.create(props);
    return created.map(new Function<Boolean, Result>() {
        ObjectNode jsonResult = Json.newObject();

        public Result apply(Boolean created) {
            if (created) {
                String name = json.get("name").asText();
                jsonResult.put("id", name);
                jsonResult.put("message", "Feature successfully created.");
                return ok(jsonResult);
            }// w  w  w  .  jav  a  2 s. c  om
            jsonResult.put("error", "Feature not created.");
            return badRequest(jsonResult);
        }
    });
}

From source file:models.service.reminder.RemindService.java

/**
 * ????/*from ww  w. ja  v a 2  s  .c o  m*/
 * 
 * @param cfg json
 * @param items ??item
 * 
 * @return true:, false:
 */
public static boolean verifyCfg(JsonNode cfg, Item[] items) {
    if (null == cfg) {
        return false;
    }

    boolean isSuccess = true;
    int count = 0;
    for (Item item : items) {
        if (!item.isEnable) {
            continue;
        }

        String itemVal = item.getVal();

        // ??
        if (cfg.hasNonNull(itemVal) && cfg.get(itemVal).isArray()) {
            JsonNode optionsNode = cfg.get(itemVal);
            Iterator<JsonNode> optionsIt = optionsNode.elements();

            // ??
            Set<String> optionSet = new HashSet<>();
            while (optionsIt.hasNext()) {
                String optionString = optionsIt.next().asText();

                if (!Option.isContainVal(optionString)) {
                    isSuccess = false;
                    break;
                }

                optionSet.add(optionString);
            }
            if (!isSuccess) {
                break;
            }

            // ?????
            if (optionSet.size() != optionsNode.size()) {
                isSuccess = false;
                break;
            }

            count++;
        } else {
            isSuccess = false;
            break;
        }
    }

    // ?
    if (cfg.size() > count) {
        isSuccess = false;
    }

    return isSuccess;
}

From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java

private static void parseListValues(List<String> values, JsonNode valuesNode) {
    if (valuesNode != null && (valuesNode.size() > 0)) {
        for (int i = 0; i < valuesNode.size(); i++) {
            String value = getValueAsString(valuesNode.get(i).get("$"));
            if (value != null) {
                values.add(value);//from   w  ww . j a v a 2  s .  com
            }
        }
    }
}

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

public static List<User> parseUserList(JsonNode node) {
    List<User> userList = new ArrayList<User>();
    final JsonNode userArray = node.get(Keys.User.LIST);

    if (userArray != null && userArray.isArray()) {
        for (final JsonNode userNode : userArray) {
            User u = parseUser(userNode);
            // assign and check null and do not add local user
            if (u != null) {
                userList.add(u);/*  w  ww.  j a v a2s  . c om*/
            }
        }
    } else {
        logError("Parse Users", node);
    }

    return userList;
}