I have the following function that a Json generates with all the contents of a directory:
public static void generateReport(File dir, JSONArray content) throws IOException, ParseException {
File listFile[] = dir.listFiles();
String md5;
if (listFile != null && listFile.length > 0) {
for (int i = 0; i < listFile.length; i++) {
JSONObject obj = new JSONObject();
content.add(obj);
if (listFile[i].isDirectory()) {
md5 = md5OfString(listFile[i].getAbsolutePath());
obj.put("md5", md5);
obj.put("type", "folder");
obj.put("path", listFile[i].getAbsolutePath());
JSONArray contentSon = new JSONArray();
obj.put("Content", contentSon);
generateReport(listFile[i], contentSon);
//numDir++;
} else if (listFile[i].isFile()) {
md5 = md5OfFile(listFile[i]);
obj.put("md5", md5);
obj.put("type", "file");
obj.put("path", listFile[i].getAbsolutePath());
//numFiles++;
}
}
}
}
Calling this function twice, with different parameters, would generate two JSONs with different data. What I need is to compare both generated JSONs and generate a new JSON with the differences between the other two.
Ex of report of differences:
{
"root": "/u/data/Coldview/apps",
"origin-report": "informe.json",
"diff": [
{
"type": "folder",
"path": "ldf.web.ejecuciondeprotestos",
"origin-md5": ".........",
"destination-md5": "........."
},
{
"type": "folder",
"path": "ldf.web.ejecuciondeprotestos/lib",
"origin-md5": ".........",
"destination-md5": "........."
},
{
"type": "file",
"name": "AMCOX.Core.jar",
"origin-md5": ".........",
"destination-md5": "........."
}
]
}
What I do not know is how to compare my two JSON objects and get the differences between them.
I'm using the Json-Simple library
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
but it does not seem to have any method for what I need because of what I'm seeing if I have to change the library or that!
Thanks for the help, advice, etc.
Greetings!