Segment parseArrayAccess(boolean acceptBracket) { Object object = parseArrayAccessFilter(acceptBracket); if (object instanceof Segment) { return ((Segment) object); } return new FilterSegment((Filter) object); }
public String toString() { return JSON.toJSONString(this); } }
public Object eval(JSONPath path, Object rootObject, Object currentObject) { List<Object> items = new JSONArray(indexes.length); for (int i = 0; i < indexes.length; ++i) { Object item = path.getArrayItem(currentObject, indexes[i]); items.add(item); } return items; }
/** * Compile jsonPath and use it to extract keySet or field names from rootObject. * * @param rootObject Can be a map or custom object. Array and Collection are not supported. * @param path JSONPath string to be compiled. * @return Set of keys, or <code>null</code> if not supported. */ public static Set<?> keySet(Object rootObject, String path) { JSONPath jsonpath = compile(path); Object result = jsonpath.eval(rootObject); return jsonpath.evalKeySet(result); }
public <T> T readObject(TypeReference<T> typeRef) { return readObject(typeRef.getType()); }
Filter filterRest(Filter filter) { boolean and = ch == '&'; if ((ch == '&' && getNextChar() == '&') || (ch == '|' && getNextChar() == '|')) { next(); next(); while (ch == ' ') { next(); } Filter right = (Filter) parseArrayAccessFilter(false); filter = new FilterGroup(filter, right, and); } return filter; }
public void startObject() { if (context == null) { context = new JSONStreamContext(null, JSONStreamContext.StartObject); } else { startStructure(); context = new JSONStreamContext(context, JSONStreamContext.StartObject); } this.parser.accept(JSONToken.LBRACE, JSONToken.IDENTIFIER); }
void accept(char expect) { if (ch != expect) { throw new JSONPathException("expect '" + expect + ", but '" + ch + "'"); } if (!isEOF()) { next(); } }
public void setValue(JSONPath path, Object parent, Object value) { if (deep) { path.deepSet(parent, propertyName, propertyNameHash, value); } else { path.setPropertyValue(parent, propertyName, propertyNameHash, value); } }
public boolean apply(JSONPath path, Object rootObject, Object currentObject, Object item) { Object propertyValue = path.getPropertyValue(item, propertyName, propertyNameHash); return propertyValue != null; } }
public final void skipWhitespace() { for (;;) { if (ch <= ' ' && (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t' || ch == '\f' || ch == '\b')) { next(); continue; } else { break; } } }
public boolean remove(JSONPath path, Object parent) { return path.removePropertyValue(parent, propertyName); } }
public void startArray() { if (context == null) { context = new JSONStreamContext(null, StartArray); } else { startStructure(); context = new JSONStreamContext(context, StartArray); } this.parser.accept(JSONToken.LBRACKET); }
public boolean apply(JSONPath path, Object rootObject, Object currentObject, Object item) { Object propertyValue = path.getPropertyValue(item, propertyName, propertyNameHash); return propertyValue == null; } }