how to retrieve a list of response object in java

23 Views Asked by At

I have this app that the server returns a List of type ViewVisitResponse. I am having a problem on how to retrieve the response and store it so that I can save it. This is what I tried. I really need a way to retrieve it my Api call interface has this method that returns a list of ViewVisitResponse

@POST("")
Call<List<ViewVisitResponse>> viewAllVisit(@Body ViewAllVisitModel viewAllVisitModel);

I tried to get the response using this approach, but I can't succeed in it.

try {
  if (cancelRequest) {
    return;
  }
  Response response = viewAllVisit(viewAllVisitModel).execute();
  if (response.code() == 200) {
    List<ViewVisitResponse> viewVisitResponse = new ArrayList<>((ViewVisitResponse)) response.body();
    viewAllVisitResponseData.postValue(viewVisitResponse);
  } else {
    viewAllVisitResponseData.postValue(null);
  }
} catch (Exception e) {
  e.printStackTrace();
  viewAllVisitResponseData.postValue(null);
}
0

There are 0 best solutions below