Package org.mockserver.matchers
Interface CustomJsonUnitMatcherProvider
-
public interface CustomJsonUnitMatcherProviderPlug-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
CustomJsonUnitMatcherLoaderwhen themockserver.customJsonUnitMatchersClassconfiguration property names a fully qualified class. The class must have a public no-arg constructor.The returned
Matchers are registered against the json-unitConfigurationused 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:
Then start MockServer withpublic 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; } }-Dmockserver.customJsonUnitMatchersClass=com.example.MyMatchersand reference the matcher in a JSON body expectation:{ "price": "${json-unit.matches:largerThan}" }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<String,org.hamcrest.Matcher<?>>jsonUnitMatchers()Returns the named matchers to register with json-unit.
-