Class RequestBodyExtractionHelper
java.lang.Object
org.mockserver.templates.engine.helpers.RequestBodyExtractionHelper
Shared JSONPath / XPath extraction helper used by the Velocity and JavaScript template engines so
those engines extract request-body fields with the exact same underlying libraries, error handling
and return semantics as the Mustache engine's
jsonPath / xPath lambdas.
Both methods operate on the current request body (via HttpRequest.getBodyAsJsonOrXmlString()).
On a missing path or any evaluation error they mirror Mustache: the error is logged and an empty
value is returned (empty string for xPath, empty string for jsonPath) rather than
throwing, so a template that references a non-existent path still renders.
- Author:
- jamesdbloom
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVelocity tool exposing JSONPath extraction as$jsonPath.find("$.field")(and$jsonPath.jsonPath(...)).static classVelocity tool exposing XPath extraction as$xPath.find("//field")(and$xPath.xPath(...)). -
Constructor Summary
ConstructorsConstructorDescriptionRequestBodyExtractionHelper(HttpRequest request, MockServerLogger mockServerLogger) -
Method Summary
Modifier and TypeMethodDescriptionEvaluate a JSONPath expression against the request body.toString()Evaluate an XPath expression against the request body, returning the result as a string (the sameXPathConstants.STRINGreturn type the Mustache engine uses), or an empty string if the path is missing or evaluation fails.
-
Constructor Details
-
RequestBodyExtractionHelper
-
-
Method Details
-
jsonPath
Evaluate a JSONPath expression against the request body. Returns the extracted value (which may be a scalar, list or map depending on the expression), or an empty string if the path is missing, resolves to a JSONnull, or evaluation fails. (Templates rendernullas empty anyway, so coercing to""keeps Velocity/JavaScript output consistent with Mustache.) -
xPath
Evaluate an XPath expression against the request body, returning the result as a string (the sameXPathConstants.STRINGreturn type the Mustache engine uses), or an empty string if the path is missing or evaluation fails. -
toString
-