private static Entry entryFromJsonObject(JSONObject object) { String file = object.get(ManifestConstants.FILE).toString(); String hash = object.get(ManifestConstants.HASH).toString(); String time = object.get(ManifestConstants.TIME).toString(); String size = object.get(ManifestConstants.SIZE).toString(); String type = object.get(ManifestConstants.TYPE).toString(); EntryStatus statType = EntryStatus.valueOf(type); return new Entry( file, hash, Util.longFromStringWithoutThrow(time), Util.longFromStringWithoutThrow(size), statType); }
public static Manifest manifestFromJSonObject(JSONObject parsedObject) { String versionStr = ""; String guid = ""; String urlRoot = ""; Object tmp = parsedObject.get(ManifestConstants.VERSION); if (null != tmp) { versionStr = tmp.toString(); } tmp = parsedObject.get(ManifestConstants.GUID); if (null != tmp) { guid = tmp.toString(); } tmp = parsedObject.get(ManifestConstants.URLROOT); if (null != tmp) { urlRoot = tmp.toString(); } Manifest toReturn = new Manifest(Util.intFromStringWithoutThrow(versionStr), guid, urlRoot); tmp = parsedObject.get(ManifestConstants.ENTRIES); if (tmp instanceof JSONArray) { JSONArray entries = (JSONArray) tmp; for (Object tmpEntry : entries) { if (tmpEntry instanceof JSONObject) { Entry e = entryFromJsonObject((JSONObject) tmpEntry); if (null != e) { toReturn.addEntry(e); } } } } return toReturn; }