Example usage for com.fasterxml.jackson.core JsonPointer mayMatchElement

List of usage examples for com.fasterxml.jackson.core JsonPointer mayMatchElement

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonPointer mayMatchElement.

Prototype

public boolean mayMatchElement() 

Source Link

Usage

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 a2  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);
}