Package de.xima.fc.helper
Class JsonPathBuilder
- java.lang.Object
-
- de.xima.fc.helper.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 Summary
Constructors Constructor Description JsonPathBuilder(String root)Creates a new JSON path builder with the given root.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringbuild()JsonPathBuilderenterArray(int index)Adds an array element to the JSON path.JsonPathBuilderenterObject(String fieldName)Adds an object property to the JSON path.JsonPathBuilderleave()Leaves the most recently added array item or object property, i.e.
-
-
-
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:
buildin interfaceorg.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.
-
-