Search in sources :

Example 1 with JsonDiff

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);
    }
}
Also used : JsonDiff(org.batfish.common.util.JsonDiff) JsonDiffAnswerElement(org.batfish.datamodel.answers.JsonDiffAnswerElement) JSONObject(org.codehaus.jettison.json.JSONObject) JsonDiffAnswerElement(org.batfish.datamodel.answers.JsonDiffAnswerElement) AnswerElement(org.batfish.datamodel.answers.AnswerElement) JSONException(org.codehaus.jettison.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonDiff (org.batfish.common.util.JsonDiff)1 AnswerElement (org.batfish.datamodel.answers.AnswerElement)1 JsonDiffAnswerElement (org.batfish.datamodel.answers.JsonDiffAnswerElement)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1