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