List of usage examples for com.fasterxml.jackson.core JsonPointer tail
public JsonPointer tail()
From source file:com.meltmedia.dropwizard.crypto.JsonPointerEditor.java
public JsonNode setValue(JsonNode value) { JsonPointer currentPointer = pointer; JsonNode currentNode = root;/*from w w w . ja v a 2s . c o m*/ JsonNode parentNode = null; String matchingProperty = null; int matchingIndex = -1; while (!"".equals(currentPointer.getMatchingProperty())) { parentNode = currentNode; matchingProperty = currentPointer.getMatchingProperty(); matchingIndex = currentPointer.getMatchingIndex(); currentNode = currentNode.get(matchingProperty); currentPointer = currentPointer.tail(); } if (parentNode == null) { root = value; } else if (parentNode instanceof ObjectNode) { ((ObjectNode) parentNode).set(matchingProperty, value); } else if (parentNode instanceof ArrayNode) { ((ArrayNode) parentNode).set(matchingIndex, value); } return value; }
From source file:io.progix.dropwizard.patch.explicit.JsonPath.java
/** * Creates the path using a {@link JsonPointer} by iterating through the segments and creating {@link * JsonPathProperty} and {@link JsonPathElement} for each segment. * <p/>/* ww w . j av a 2 s. co m*/ * If a given segment does not match as a String property, an empty {@link JsonPathProperty} is created. * <p/> * If a given segment does not match as a Integer index, an empty {@link JsonPathElement} is created. * * @param pointer */ public JsonPath(JsonPointer pointer) { this.properties = new ArrayList<>(); this.elements = new ArrayList<>(); this.pathString = ""; while (pointer != null) { if (pointer.mayMatchProperty() && !pointer.getMatchingProperty().isEmpty()) { properties.add(new JsonPathProperty(pointer.getMatchingProperty())); this.pathString += pointer.getMatchingProperty() + "/"; } else if (pointer.getMatchingProperty().equals("-")) { /* This character represents the last element in an array */ elements.add(new JsonPathElement(true)); this.pathString += pointer.getMatchingProperty() + "/"; } else { properties.add(new JsonPathProperty()); } if (pointer.mayMatchElement()) { elements.add(new JsonPathElement(pointer.getMatchingIndex())); this.pathString += pointer.getMatchingIndex() + "/"; } else { elements.add(new JsonPathElement()); } pointer = pointer.tail(); } this.pathString = this.pathString.substring(0, this.pathString.length() - 1); }