private T parseJson(JsonTypedInput input, Class dataClass) {
   T parsedObject = null;
   try {
     parsedObject = (T) RestClient.getConverter().fromBody(input, dataClass);
   } catch (ConversionException e) {
     Log.e("Response conversion", e.getLocalizedMessage());
   }
   return parsedObject;
 }
 private static ImportSummary getPostImportSummary(Response response) {
   ImportSummary importSummary = null;
   try {
     String body = new StringConverter().fromBody(response.getBody(), String.class);
     Log.d(CLASS_TAG, body);
     importSummary =
         DhisController.getInstance().getObjectMapper().readValue(body, ImportSummary.class);
   } catch (IOException e) {
     e.printStackTrace();
   } catch (ConversionException e) {
     e.printStackTrace();
   }
   return importSummary;
 }
 private static ImportSummary getPutImportSummary(Response response) {
   ApiResponse apiResponse = null;
   try {
     String body = new StringConverter().fromBody(response.getBody(), String.class);
     Log.d(CLASS_TAG, body);
     apiResponse =
         DhisController.getInstance().getObjectMapper().readValue(body, ApiResponse.class);
     if (apiResponse != null
         && apiResponse.getImportSummaries() != null
         && !apiResponse.getImportSummaries().isEmpty()) {
       return (apiResponse.getImportSummaries().get(0));
     }
   } catch (IOException e) {
     e.printStackTrace();
   } catch (ConversionException e) {
     e.printStackTrace();
   }
   return null;
 }
 private static ImportSummary getImportSummary(Response response) {
   // because the web api almost randomly gives the responses in different forms, this
   // method checks which one it is that is being returned, and parses accordingly.
   try {
     JsonNode node =
         DhisController.getInstance()
             .getObjectMapper()
             .readTree(new StringConverter().fromBody(response.getBody(), String.class));
     if (node == null) {
       return null;
     }
     if (node.has("response")) {
       return getPutImportSummary(response);
     } else {
       return getPostImportSummary(response);
     }
   } catch (IOException e) {
     e.printStackTrace();
   } catch (ConversionException e) {
     e.printStackTrace();
   }
   return null;
 }
 @Override
 public void success(JsonObject jsonObject, Response response) {
   // since 09.06.2015 API settings changed, so only "success" responses will be processed here
   JsonElement responseData = extractData(mKeys, jsonObject);
   if (mSuccessAction != NO_ACTION) {
     performAction(mSuccessAction, responseData);
   }
   //        if (responseData==null) {
   //            mListener.onSuccess();
   //        } else {
   if (isArrayResponse) {
     JsonArray array = responseData.getAsJsonArray();
     if (mBaseTypeName == null) {
       ArrayList<T> parsedArray = new ArrayList<>();
       for (int i = 0; i < array.size(); i++) {
         T item = parseJson(new JsonTypedInput(array.get(i)));
         if (item != null) {
           parsedArray.add(item);
         }
       }
       mListener.onSuccess(parsedArray);
       // if mBaseTypeName set, use parsing with subclasses of base class
     } else if ("Coupon".contentEquals(mBaseTypeName)) {
       ArrayList<Coupon> parsedArray1 =
           new ArrayList<>(); // list items can be Coupon, SimpleDeal or GroupDeal
       for (int i = 0; i < array.size(); i++) {
         JsonObject raw_item = array.get(i).getAsJsonObject();
         String type = raw_item.get("alias").getAsString();
         Coupon item = null;
         try {
           item = parseOffer(new JsonTypedInput(array.get(i)), type);
           if (item != null) {
             parsedArray1.add(item);
           }
         } catch (ConversionException e) {
           e.printStackTrace();
         } catch (ClassNotFoundException e) {
           e.printStackTrace();
         }
       }
       mListener.onSuccess((ArrayList<T>) parsedArray1);
     }
   } else {
     if (mBaseTypeName == null) {
       T parsedObject = parseJson(new JsonTypedInput(responseData));
       mListener.onSuccess(parsedObject);
       // if mBaseTypeName set, use parsing with subclasses of base class
     } else if ("Coupon".contentEquals(mBaseTypeName)) {
       String type = responseData.getAsJsonObject().get("alias").getAsString();
       Coupon parsedObject1 = null;
       try {
         parsedObject1 = parseOffer(new JsonTypedInput(responseData), type);
       } catch (ConversionException e) {
         e.printStackTrace();
       } catch (ClassNotFoundException e) {
         e.printStackTrace();
       }
       if (parsedObject1 != null) {
         mListener.onSuccess((T) parsedObject1);
       }
     }
   }
   //        }
 }