Class CustomJsonUnitMatcherLoader

java.lang.Object
org.mockserver.matchers.CustomJsonUnitMatcherLoader

public final class CustomJsonUnitMatcherLoader extends Object
Loads the CustomJsonUnitMatcherProvider class named by mockserver.customJsonUnitMatchersClass and exposes the matchers it produces.

The provider class is instantiated once via its public no-arg constructor and its matcher map is cached for the JVM lifetime keyed on the class name, so changing the configuration property at runtime (e.g. between tests) picks up the new provider on next access.

If the property is blank, the named class cannot be loaded, the class does not implement CustomJsonUnitMatcherProvider, or any exception is thrown during instantiation, an empty map is returned and a WARN log entry is written - matching is never failed because of a misconfigured provider.

  • Method Details

    • load

      public static Map<String,org.hamcrest.Matcher<?>> load()
      Returns the named matchers contributed by the configured provider, or an empty map if no provider is configured or the provider cannot be loaded.
    • load

      public static Map<String,org.hamcrest.Matcher<?>> load(Configuration configuration)
      As load() but preferring the customJsonUnitMatchersClass value carried on the supplied Configuration instance, falling back to the static ConfigurationProperties store when it is null. This is what makes a provider class configured over PUT /mockserver/configuration actually load.
      Parameters:
      configuration - the live server configuration, or null to read the static store
    • reset

      public static void reset()
      Clears the cached provider so the next call to load() re-reads the configuration property and re-instantiates the provider. Intended for tests that change the property between cases.