use of com.meniga.sdk.models.offers.reimbursementaccounts.MenigaReimbursementAccountTypePage in project mobile-sdk-android by meniga.
the class MenigaReimbursementAccountConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfAccount = new TypeToken<MenigaReimbursementAccount>() {
}.getType();
Type typeOfAccounts = new TypeToken<MenigaReimbursementAccountPage>() {
}.getType();
Type typeOfAccountTypes = new TypeToken<MenigaReimbursementAccountTypePage>() {
}.getType();
if (typeOfAccount.equals(type)) {
return new Converter<ResponseBody, MenigaReimbursementAccount>() {
@Override
public MenigaReimbursementAccount convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
return gson.fromJson(getAsObject(resBody.byteStream()), MenigaReimbursementAccount.class);
}
};
} else if (typeOfAccounts.equals(type)) {
return new Converter<ResponseBody, MenigaReimbursementAccountPage>() {
@Override
public MenigaReimbursementAccountPage convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaReimbursementAccountPage page = new MenigaReimbursementAccountPage();
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonElement jelement;
try {
jelement = new JsonParser().parse(isr);
} finally {
isr.close();
}
JsonObject jobject = jelement.getAsJsonObject();
JsonArray arr = jobject.getAsJsonArray("data");
Collections.addAll(page, gson.fromJson(arr, MenigaReimbursementAccount[].class));
JsonObject meta = jobject.getAsJsonObject("meta");
return MenigaConverter.mergeMeta(gson, page, meta);
}
};
} else if (typeOfAccountTypes.equals(type)) {
return new Converter<ResponseBody, MenigaReimbursementAccountTypePage>() {
@Override
public MenigaReimbursementAccountTypePage convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaReimbursementAccountTypePage page = new MenigaReimbursementAccountTypePage();
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonElement jelement;
try {
jelement = new JsonParser().parse(isr);
} finally {
isr.close();
}
JsonObject jobject = jelement.getAsJsonObject();
JsonArray arr = jobject.getAsJsonArray("data");
Collections.addAll(page, gson.fromJson(arr, MenigaReimbursementAccountType[].class));
JsonObject meta = jobject.getAsJsonObject("meta");
return MenigaConverter.mergeMeta(gson, page, meta);
}
};
}
return null;
}
Aggregations