Refine search
/** * Convenience method that is functionally equivalent to: *<pre> * return at(JsonPointer.valueOf(jsonPointerExpression)); *</pre> *<p> * Note that if the same expression is used often, it is preferable to construct * {@link JsonPointer} instance once and reuse it: this method will not perform * any caching of compiled expressions. * * @param jsonPtrExpr Expression to compile as a {@link JsonPointer} * instance * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link TreeNode#isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(String jsonPtrExpr) { return at(JsonPointer.compile(jsonPtrExpr)); }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
protected JsonPointer _constructHead(int suffixLength, JsonPointer last) { if (this == last) { return EMPTY; } JsonPointer next = _nextSegment; String str = _asString; return new JsonPointer(str.substring(0, str.length() - suffixLength), _matchingPropertyName, _matchingElementIndex, next._constructHead(suffixLength, last)); }
protected JsonPointer _constructHead() { // ok; find out who we are to drop JsonPointer last = last(); if (last == this) { return EMPTY; } // and from that, length of suffix to drop int suffixLength = last._asString.length(); JsonPointer next = _nextSegment; return new JsonPointer(_asString.substring(0, _asString.length() - suffixLength), _matchingPropertyName, _matchingElementIndex, next._constructHead(suffixLength, last)); }
@Override public TokenFilter includeElement(int index) { JsonPointer next = _pathToMatch.matchElement(index); if (next == null) { return null; } if (next.matches()) { return TokenFilter.INCLUDE_ALL; } return new JsonPointerBasedFilter(next); }
private static void computeUnchangedObject(final Map<JsonPointer, JsonNode> ret, final JsonPointer pointer, final JsonNode source, final JsonNode target) { final Iterator<String> sourceFields = source.fieldNames(); while (sourceFields.hasNext()) { final String name = sourceFields.next(); if (!target.has(name)) { continue; } computeUnchanged(ret, pointer.append(JsonPointer.valueOf(encodeSegment(name))), source.get(name), target.get(name)); } }
private static void computeUnchangedArray(final Map<JsonPointer, JsonNode> ret, final JsonPointer pointer, final JsonNode source, final JsonNode target) { final int size = Math.min(source.size(), target.size()); for (int i = 0; i < size; i++) { computeUnchanged(ret, pointer.append(JsonPointer.valueOf("/" + i)), source.get(i), target.get(i)); } }
public void configure(@SuppressWarnings("rawtypes") Map stormConf, JsonNode filterParams) { java.util.Iterator<Entry<String, JsonNode>> iter = filterParams .fields(); while (iter.hasNext()) { Entry<String, JsonNode> entry = iter.next(); String key = entry.getKey(); JsonNode node = entry.getValue(); LabelledJsonPointer labelP = new LabelledJsonPointer(key, JsonPointer.valueOf(node.asText())); expressions.add(labelP); } }
@Override JsonNode apply(final JsonNode node) { ensureExistence(node); final JsonNode replacement = valueCopy(); if (path.toString().isEmpty()) { return replacement; } final JsonNode parent = node.at(path.head()); final String rawToken = path.last().getMatchingProperty(); if (parent.isObject()) { ((ObjectNode) parent).set(rawToken, replacement); } else { ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement); } return node; } }
/** * Build a JsonNode tree to contain the given value at the given JsonPointer * path. Empty array and object nodes are created and nested as needed. * * @param p a JsonPointer indicating where the value is to appear in the * resulting structure * @param value the value to embed in the structure * @return the created structure */ private JsonNode buildTree(JsonPointer p, JsonNode value) { if (p.matches()) { return value; } else if (p.getMatchingIndex() >= 0) { ArrayNode result = JsonNodeFactory.instance.arrayNode(); result.set(p.getMatchingIndex(), buildTree(p.tail(), value)); return result; } else { ObjectNode result = JsonNodeFactory.instance.objectNode(); result.set(p.getMatchingProperty(), buildTree(p.tail(), value)); return result; } }
private static JsonNode findRoot(JsonNode node, @Nullable String configRoot) { if (Strings.isNullOrEmpty(configRoot)) { return node; } JsonNode root = node.at(JsonPointer.valueOf(configRoot)); if (root.isMissingNode()) { return null; } return root; }
static JsonNode addToObject(final JsonPointer path, final JsonNode node, final JsonNode value) { final ObjectNode target = (ObjectNode) node.at(path.head()); target.set(path.last().getMatchingProperty(), value); return node; } }
/** * Alias for {@link #compile}; added to make instances automatically * deserializable by Jackson databind. */ public static JsonPointer valueOf(String input) { return compile(input); }
private boolean matchesPath(JsonOverlay<?> child, JsonPointer path) { JsonPointer childPath = getPointer(child); while (!childPath.matches()) { if (!childPath.matchesProperty(path.getMatchingProperty())) { return false; } else { path = path.tail(); childPath = childPath.tail(); } } return true; }
@Override public JsonOverlay<?> _findInternal(JsonPointer path) { if (path.matchesProperty("additionalProperties")) { return path.tail().matches() ? _getOverlay("additionalProperties", BooleanOverlay.class) : _get("additionalPropertiesSchema", SchemaImpl.class)._findInternal(path.tail()); } else { return super._findInternal(path); } }
@Override public String toString() { return label + " => " + pointer.toString(); } }
@Override public TokenFilter includeProperty(String name) { JsonPointer next = _pathToMatch.matchProperty(name); if (next == null) { return null; } if (next.matches()) { return TokenFilter.INCLUDE_ALL; } return new JsonPointerBasedFilter(next); }