Class JsonPathBuilder

  • All Implemented Interfaces:
    org.apache.commons.lang3.builder.Builder<String>

    public final class JsonPathBuilder
    extends Object
    implements org.apache.commons.lang3.builder.Builder<String>
    Simple builder for a JSON path. Supports array elements and object properties.
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • JsonPathBuilder

        public JsonPathBuilder​(String root)
        Creates a new JSON path builder with the given root.
        Parameters:
        root - Root of the JSON path expression, usually $.
    • Method Detail

      • build

        public String build()
        Specified by:
        build in interface org.apache.commons.lang3.builder.Builder<String>
        Returns:
        The current JSON path as a string.
      • enterArray

        public JsonPathBuilder enterArray​(int index)
        Adds an array element to the JSON path.
        Parameters:
        index - Index of the array element
        Returns:
        This builder for chaining method calls.
      • enterObject

        public JsonPathBuilder enterObject​(String fieldName)
        Adds an object property to the JSON path.
        Parameters:
        fieldName - Key of the object property.
        Returns:
        This builder for chaining method calls.
      • leave

        public JsonPathBuilder leave()
        Leaves the most recently added array item or object property, i.e. drops it from the path.
        Returns:
        This builder for chaining method calls.