I'm getting json object on my mongodb with virustotal API This is how a json object stored in mongodb object looks like :
{
"_id" : ObjectId("597cd2f871eac714388b2f7f"),
"results" : {
"scans" : {
"Bkav" : {
"detected" : true,
"version" : "1.3.0.8042",
"result" : "W32.HfsAutoB.971A",
"update" : "20160706"
},
"TotalDefense" : {
"detected" : false,
"version" : "37.1.62.1",
"result" : null,
"update" : "20160706"
},
"MicroWorld-eScan" : {
"detected" : true,
"version" : "12.0.250.0",
"result" : "Packer.Expressor.B",
"update" : "20160706"
},
"nProtect" : {
"detected" : true,
"version" : "2016-07-06.01",
"result" : "Packer.Expressor.B",
"update" : "20160706"
},
"ALYac" : {
"detected" : false,
"version" : "1.0.1.9",
"result" : null,
"update" : "20160706"
},
"TrendMicro" : {
"detected" : true,
"version" : "9.740.0.1012",
"result" : "TROJ_GEN.R047C0CAP16",
"update" : "20160706"
},
"McAfee-GW-Edition" : {
"detected" : true,
"version" : "v2015",
"result" : "BehavesLike.Win32.Flyagent.cc",
"update" : "20160706"
},
"Sophos" : {
"detected" : true,
"version" : "4.98.0",
"result" : "W32/Pidgeon-A",
"update" : "20160706"
},
"Cyren" : {
"detected" : true,
"version" : "5.4.16.7",
"result" : "W32/SysVenFak.A.gen!Eldorado",
"update" : "20160706"
},
"Microsoft" : {
"detected" : true,
"version" : "1.1.12902.0",
"result" : "Backdoor:Win32/Delf.SJ",
"update" : "20160706"
},
"AegisLab" : {
"detected" : true,
"version" : "4.2",
"result" : "Backdoor.W32.BlackHole.acx!c",
"update" : "20160706"
},
"Qihoo-360" : {
"detected" : false,
"version" : "1.0.0.1120",
"result" : null,
"update" : "20160706"
}
},
"scan_id" : "2ad6e0aad0b40f152f234787daa4afb87538f3278f5c8f815d53ef46d5eea4ac-1467833095",
"sha1" : "c5dcd5526ac5330ad1e9fad51488718329fdb697",
"resource" : "0a60424e0967b6cfc172dac82e10a2fe",
"response_code" : 1,
"scan_date" : "2016-07-06 19:24:55",
"permalink" : "https://www.virustotal.com/file/2ad6e0aad0b40f152f234787daa4afb87538f3278f5c8f815d53ef46d5eea4ac/analysis/1467833095/",
"verbose_msg" : "Scan finished, information embedded",
"total" : 54,
"positives" : 41,
"sha256" : "2ad6e0aad0b40f152f234787daa4afb87538f3278f5c8f815d53ef46d5eea4ac",
"md5" : "0a60424e0967b6cfc172dac82e10a2fe"
},
"response_code" : 200
}
As you can see the json object is too complicated to just get given value from, This is what i've tried so far :
MongoClient mongo = new MongoClient("localhost", 27017);
MongoDatabase database1 = mongo.getDatabase(db);
MongoCollection<Document> collection1 = database1.getCollection(col);
try (MongoCursor<Document> cursor = collection1.find().iterator()){
while (cursor.hasNext()){
Document doc = cursor.next();
List list = new ArrayList(doc.values());
System.out.println(list.get(1));
}
}
I was thinking maybe there is a way to map all this json to a java class, the main problem is with the "scans" as there are many different scannors and it isn't optimized to create a java class model to each of them,
My question is how can i store directly my json objects to a java object so as to operate on the results returned.