Package org.mockserver.matchers
Interface CustomJsonUnitMatcherProvider
public interface CustomJsonUnitMatcherProvider
Plug-in point for registering custom json-unit
matchers so they can be referenced from JSON body expectations using the
${json-unit.matches:name} placeholder.
An implementation is loaded reflectively by CustomJsonUnitMatcherLoader when the
mockserver.customJsonUnitMatchersClass configuration property names a fully
qualified class. The class must have a public no-arg constructor.
The returned Matchers are registered against the json-unit
Configuration used to match each request body, so the
map should be deterministic and inexpensive to produce - it is called once per provider
instance and the result is cached for the lifetime of the JVM.
Example usage:
public class MyMatchers implements CustomJsonUnitMatcherProvider {
public Map<String, Matcher<?>> jsonUnitMatchers() {
Map<String, Matcher<?>> matchers = new HashMap<>();
matchers.put("largerThan", new LargerThanMatcher(BigDecimal.valueOf(100)));
return matchers;
}
}
Then start MockServer with -Dmockserver.customJsonUnitMatchersClass=com.example.MyMatchers
and reference the matcher in a JSON body expectation:
{ "price": "${json-unit.matches:largerThan}" }
-
Method Summary
Modifier and TypeMethodDescriptionReturns the named matchers to register with json-unit.
-
Method Details
-
jsonUnitMatchers
Returns the named matchers to register with json-unit. Keys are the matcher names referenced by the${json-unit.matches:name}placeholder. Must not returnnull.
-