Class BodyMatching

java.lang.Object
org.mockserver.matchers.BodyMatching

public class BodyMatching extends Object
Shared body-matching dispatch used by BOTH request matching (HttpRequestPropertiesMatcher) and response matching (HttpResponseMatcher).

This is the single source of truth for "given a compiled BodyMatcher and an actual message body, does the body match?". It owns the full matcher dispatch the request matcher historically had inline — and which the response matcher previously lacked:

  • optional-body short-circuit — an optional template body matches a message with no body at all;
  • multipart — a MultipartMatcher decodes the raw body bytes using the Content-Type boundary;
  • binary original/compressed dual-match — a BinaryMatcher accepts a match against either the decompressed bytes or the original (e.g. still-compressed) bytes;
  • JSON / JSON schema / JSON path — the actual body is first run through JsonSchemaBodyDecoder.convertToJson(BodySource, BodyMatcher) so an XML or form actual body is converted to JSON before matching, and an absent body is tolerated (a clean non-match, never an internal NPE);
  • XML / XML schema / GraphQL / JSON-RPC / string — matched against the body string.

The dispatch is parameterised over a BodySource (the small set of accessors the dispatch needs) and an optional MatchDifference context. The request path passes a non-null context so its diagnostics are unchanged; the response path may pass null (response diagnostics are a later addition). The request-only control-plane BodyDTO re-parse fallback is intentionally NOT part of this helper — it stays on the request path.