org.mockserver.matchers.JsonStringMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.matchers;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;
/**
* @author jamesdbloom
*/
public class JsonStringMatcher extends BodyMatcher implements Matcher {
private final String matcher;
public JsonStringMatcher(String matcher) {
this.matcher = matcher;
}
public boolean matches(String matched) {
boolean result = false;
JSONCompareResult jsonCompareResult = null;
try {
jsonCompareResult = compareJSON(matcher, matched, JSONCompareMode.LENIENT);
if (jsonCompareResult.passed()) {
result = true;
}
if (!result) {
logger.trace("Failed to perform JSON match [{}] with [{}] because {}", matched, this.matcher, jsonCompareResult.getMessage());
}
} catch (Exception e) {
logger.trace("Failed to perform JSON match [{}] with [{}] because {}", matched, this.matcher, e.getMessage());
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy