use of com.meniga.sdk.models.offers.redemptions.MenigaScheduledReimbursement in project mobile-sdk-android by meniga.
the class MenigaRedemptionConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfRedemptions = new TypeToken<MenigaRedemptions>() {
}.getType();
if (typeOfRedemptions.equals(type)) {
return new Converter<ResponseBody, MenigaRedemptions>() {
@Override
public MenigaRedemptions convert(ResponseBody resBody) throws IOException {
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonElement element;
try {
element = new JsonParser().parse(isr);
} finally {
isr.close();
}
Gson gson = GsonProvider.getGsonBuilder();
MenigaRedemptions page = gson.fromJson(getAsArray(element), MenigaRedemptions.class);
JsonObject object = element.getAsJsonObject();
JsonObject meta = object.getAsJsonObject("meta");
List<MenigaScheduledReimbursement> cashBackRaw = gson.fromJson(meta.getAsJsonArray("scheduledReimbursements"), new TypeToken<List<MenigaScheduledReimbursement>>() {
}.getType());
MenigaRedemptions main = MenigaConverter.mergeMeta(gson, page, meta);
main.setScheduledReimbursement(cashBackRaw);
return main;
}
};
}
return null;
}
Aggregations