use of org.batfish.common.util.JsonDiff in project batfish by batfish.
the class Answerer method answerDiff.
// this is the default differential answerer
// if you want a custom one for a subclass, override this function in the
// subclass
public AnswerElement answerDiff() {
_batfish.pushBaseEnvironment();
_batfish.checkEnvironmentExists();
_batfish.popEnvironment();
_batfish.pushDeltaEnvironment();
_batfish.checkEnvironmentExists();
_batfish.popEnvironment();
_batfish.pushBaseEnvironment();
AnswerElement before = create(_question, _batfish).answer();
_batfish.popEnvironment();
_batfish.pushDeltaEnvironment();
AnswerElement after = create(_question, _batfish).answer();
_batfish.popEnvironment();
try {
String beforeJsonStr = BatfishObjectMapper.writePrettyString(before);
String afterJsonStr = BatfishObjectMapper.writePrettyString(after);
JSONObject beforeJson = new JSONObject(beforeJsonStr);
JSONObject afterJson = new JSONObject(afterJsonStr);
JsonDiff diff = new JsonDiff(beforeJson, afterJson);
return new JsonDiffAnswerElement(diff);
} catch (JsonProcessingException | JSONException e) {
throw new BatfishException("Could not convert diff element to json string", e);
}
}
Aggregations