Source:
public Product parseResponse(String response) throws JSONException { JSONObject jsonProduct = new JSONObject(response); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); jsonProduct = (JSONObject) jsonProduct.get("product"); Product result = null; try { String expirationStr = null; Date expirationDate = null; if (jsonProduct.has("expiration_date")) { expirationStr = jsonProduct.getString("expiration_date"); } if (expirationStr == null || expirationStr.equals("null") || expirationStr.equals("0000-00-00 00:00:00")) { expirationDate = null; } else { expirationDate = formatter.parse(expirationStr); } String displayPrice = ""; String currencyCode = ""; if (jsonProduct.has("display_price")) { displayPrice = jsonProduct.getString("display_price"); } if (jsonProduct.has("currency_code")) { currencyCode = jsonProduct.getString("currency_code"); } int numPendingOrders = 0, numProcessingOrders = 0; if (jsonProduct.get("order_counts") instanceof JSONObject) { JSONObject jsonObject = jsonProduct.getJSONObject("order_counts"); if (jsonObject.has("Pending")) { numPendingOrders = jsonObject.getInt("Pending"); } if (jsonObject.has("Processing")) { numProcessingOrders = jsonObject.getInt("Processing"); } } result = new Product( Integer.parseInt(jsonProduct.getString("product_id")), jsonProduct.getString("title"), jsonProduct.getString("description"), jsonProduct.getString("location"), resolveCategories(jsonProduct.getJSONArray("categories")), "SI Unit", jsonProduct.getString("price"), displayPrice, currencyCode, jsonProduct.getInt("quantity"), expirationDate, Uri.parse(jsonProduct.getString("thumb_image")), parseAuxImages(jsonProduct.getJSONArray("images")), jsonProduct.getInt("status"), numPendingOrders, numProcessingOrders ); } catch (ParseException e) { e.printStackTrace(); } return result; }

Target:
public Product parseResponse(String response) throws JSONException { JSONObject jsonProduct = new JSONObject(response); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); jsonProduct = (JSONObject) jsonProduct.get("product"); Product result = null; try { String expirationStr = null; Date expirationDate = null; if (jsonProduct.has("expiration_date")) { expirationStr = jsonProduct.getString("expiration_date"); } if (expirationStr == null || expirationStr.equals("null") || expirationStr.equals("0000-00-00 00:00:00")) { expirationDate = null; } else { expirationDate = formatter.parse(expirationStr); } String displayPrice = ""; String currencyCode = ""; if (jsonProduct.has("display_price")) { displayPrice = jsonProduct.getString("display_price"); } if (jsonProduct.has("currency_code")) { currencyCode = jsonProduct.getString("currency_code"); } int numPendingOrders = 0, numProcessingOrders = 0; if (jsonProduct.has("order_counts") && jsonProduct.get("order_counts") instanceof JSONObject) { JSONObject jsonObject = jsonProduct.getJSONObject("order_counts"); if (jsonObject.has("Pending")) { numPendingOrders = jsonObject.getInt("Pending"); } if (jsonObject.has("Processing")) { numProcessingOrders = jsonObject.getInt("Processing"); } } result = new Product( Integer.parseInt(jsonProduct.getString("product_id")), jsonProduct.getString("title"), jsonProduct.getString("description"), jsonProduct.getString("location"), resolveCategories(jsonProduct.getJSONArray("categories")), "SI Unit", jsonProduct.getString("price"), displayPrice, currencyCode, jsonProduct.getInt("quantity"), expirationDate, Uri.parse(jsonProduct.getString("thumb_image")), parseAuxImages(jsonProduct.getJSONArray("images")), jsonProduct.getInt("status"), numPendingOrders, numProcessingOrders ); } catch (ParseException e) { e.printStackTrace(); } return result; }