private boolean isValidPath(Object object, Object path) { if (isArray(object) && path instanceof Integer) { return true; } if (isObject(object) && path instanceof String) { return true; } return false; }
/** * <p> * Retrieve a list of JsonSimple objects found on the given path. Note that * this is a utility function, and not designed for data traversal. It * <b>will</b> only retrieve valid JsonObjects found on the provided node, * and wrap them in JsonSimple objects. * </p> * * <p> * Other objects found on that path will be ignored, and if the path itself * is not a JSONArray or not found, the function will return NULL. * </p> * * @param path : An array of indeterminate length to use as the path * @return List<JsonSimple> : A list of JSONSimple objects, or null */ public List<JsonSimple> getJsonSimpleList(Object... path) { JSONArray array = getArray(path); if (isArray(array)) { return JsonSimple.toJavaList(array); } return null; }
/** * <p> * Walk down the JSON nodes specified by the path and retrieve the target * array, writing each node that doesn't exist along the way. * </p> * * <p> * Note, when addressing path segments that are array indices you can use * '-1' to indicate that the next object should always be created fresh * and appended to the array. * </p> * * <p> * Array indices that are standard (ie. not -1) integers will be read as * normal, but return a null value from the method if they are not found. * This method will not attempt to write to a non-existing index of an * array. * </p> * * @param path : Variable length array of path segments * @return JSONArray : The target node, or NULL if path is invalid */ public JSONArray writeArray(Object... path) { Object response = writePath(new JSONArray(), path); if (isArray(response)) { return (JSONArray) response; } // The node already exists and it is not an array return null; }
/** * Retrieve the given node from the provided object. * * @param path : An array of indeterminate length to use as the path * @return JsonObject : The JSON representation */ private Object getNode(Object object, Object path) { if (isArray(object)) { try { return ((JSONArray) object).get((Integer) path); } catch(ArrayIndexOutOfBoundsException ex) { return null; } } if (isObject(object)) { return ((JsonObject) object).get(path); } return null; }
Object target = getPath(path); List<String> response = new LinkedList<String>(); if (isArray(target)) { if (substitueProperties) { List<String> temp = JsonSimple.getStringList((JSONArray) target);
if (isArray(value)) { List<JsonSimple> grandChildren = JsonSimple.toJavaList((JSONArray) value);