@Test public void parseJSONTest__album() throws IOException, JSONException { URL resource = Resources.getResource("get-album-1.json"); String string = Resources.toString(resource, Charsets.UTF_8); JSONObject jsonResult = (JSONObject) new JSONTokener(string) .nextValue(); Item item = ItemUtils.parseJSONToItem(jsonResult); assertEquals("http: Entity entity = item.getEntity(); assertEquals(1,entity.getId()); assertEquals(0,entity.getCaptured()); assertEquals(1276227460,entity.getCreated()); assertEquals("",entity.getDescription()); assertEquals(0,entity.getHeight()); assertEquals(1,entity.getLevel()); assertEquals(null,entity.getMimeType()); assertEquals(null,entity.getName()); assertEquals(2,entity.getOwnerId()); assertEquals(0f,entity.getRandKey(),0); assertEquals(0,entity.getResizeHeight()); assertEquals(0,entity.getResizeWidth()); assertEquals(null,entity.getSlug()); assertEquals("weight",entity.getSortColumn()); assertEquals("ASC",entity.getSortOrder()); assertEquals(200,entity.getThumbHeight()); assertEquals(150,entity.getThumbWidth()); assertEquals("Gallery",entity.getTitle()); assertEquals("album",entity.getType()); assertEquals(1276227718,entity.getUpdated()); assertEquals(8,entity.getViewCount()); assertEquals(0,entity.getWidth()); assertEquals(1,entity.getView1()); assertEquals(1,entity.getView2()); assertEquals("http: assertEquals("http: assertEquals("http: assertEquals(17151,entity.getThumbSize()); assertEquals("http: assertEquals(false,entity.isCanEdit()); RelationShips relationShips = item.getRelationships(); assertEquals("http: assertEquals(new HashSet<String>(),relationShips.getTags().getMembers()); assertEquals("http: Collection<String> members = new HashSet<String>(); members.add("http: members.add("http: assertEquals(members, item.getMembers()); }
public static Item parseJSONToItem(JSONObject jsonResult) throws JSONException { logger.debug("parseJSONToItem jsonResult: {}",jsonResult); Item item = new Item(); item.setUrl(jsonResult.getString("url")); item.setEntity(parseJSONToEntity(jsonResult)); item.setRelationships(parseJSONToRelationShips(jsonResult)); if (item.getEntity().getType().equals("album")) { JSONArray jsonArray = jsonResult.getJSONArray("members"); item.getMembers().addAll(convertJSONArrayToList(jsonArray)); } logger.debug("item : {}",item); return item; }
ItemUtils { public static Item parseJSONToItem(JSONObject jsonResult) throws JSONException { logger.debug("parseJSONToItem jsonResult: {}",jsonResult); Item item = new Item(); item.setUrl(jsonResult.getString("url")); item.setEntity(parseJSONToEntity(jsonResult)); item.setRelationships(parseJSONToRelationShips(jsonResult)); if (item.getEntity().getType().equals("album")) { JSONArray jsonArray = jsonResult.getJSONArray("members"); item.getMembers().addAll(convertJSONArrayToList(jsonArray)); } logger.debug("item : {}",item); return item; } }
ItemUtils { public static Item parseJSONToItem(JSONObject jsonResult) throws JSONException { logger.debug("parseJSONToItem jsonResult: {}",jsonResult); Item item = new Item(); item.setUrl(jsonResult.getString("url")); item.setEntity(parseJSONToEntity(jsonResult)); item.setRelationships(parseJSONToRelationShips(jsonResult)); if (item.getEntity().getType().equals("album")) { JSONArray jsonArray = jsonResult.getJSONArray("members"); item.getMembers().addAll(convertJSONArrayToList(jsonArray)); } logger.debug("item : {}",item); return item; }  }
ItemUtils { public static Item parseJSONToItem(JSONObject jsonResult) throws JSONException { logger.debug("parseJSONToItem jsonResult: {}",jsonResult); Item item = new Item(); item.setUrl(jsonResult.getString("url")); item.setEntity(parseJSONToEntity(jsonResult)); item.setRelationships(parseJSONToRelationShips(jsonResult)); if (item.getEntity().getType().equals("album")) { JSONArray jsonArray = jsonResult.getJSONArray("members"); item.getMembers().addAll(convertJSONArrayToList(jsonArray)); } logger.debug("item : {}",item); return item; }  static Item parseJSONToItem(JSONObject jsonResult); static List<Item> parseJSONToMultipleItems(JSONObject jsonResult); static String convertAlbumEntityToJSON(Entity entity); static String convertPhotoEntityToJSON(Entity entity); static NameValuePair convertJSONStringToNameValuePair(String value); static String convertJsonResultToApiKey(String jsonResult); static String convertJsonStringToUrl(String jsonResult); static Integer getItemIdFromUrl(String createdAlbumUrl); }
ItemUtils { public static Item parseJSONToItem(JSONObject jsonResult) throws JSONException { logger.debug("parseJSONToItem jsonResult: {}",jsonResult); Item item = new Item(); item.setUrl(jsonResult.getString("url")); item.setEntity(parseJSONToEntity(jsonResult)); item.setRelationships(parseJSONToRelationShips(jsonResult)); if (item.getEntity().getType().equals("album")) { JSONArray jsonArray = jsonResult.getJSONArray("members"); item.getMembers().addAll(convertJSONArrayToList(jsonArray)); } logger.debug("item : {}",item); return item; }  static Item parseJSONToItem(JSONObject jsonResult); static List<Item> parseJSONToMultipleItems(JSONObject jsonResult); static String convertAlbumEntityToJSON(Entity entity); static String convertPhotoEntityToJSON(Entity entity); static NameValuePair convertJSONStringToNameValuePair(String value); static String convertJsonResultToApiKey(String jsonResult); static String convertJsonStringToUrl(String jsonResult); static Integer getItemIdFromUrl(String createdAlbumUrl);  }