use of com.meniga.sdk.models.transactions.MenigaTransactionUpdate in project mobile-sdk-android by meniga.
the class MenigaTransactionUpdateConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, final Retrofit retrofit) {
Type typeOfTransactionUpdate = new TypeToken<MenigaTransactionUpdate>() {
}.getType();
if (typeOfTransactionUpdate.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public Object convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
InputStreamReader isr = null;
try {
isr = new InputStreamReader(resBody.byteStream());
JsonElement element = new JsonParser().parse(isr);
isr.close();
JsonObject json = element.getAsJsonObject();
List<MenigaTransaction> updatedTransactions = new ArrayList<>();
if (json.get("data").isJsonArray()) {
updatedTransactions = gson.fromJson(json.getAsJsonArray("data"), new TypeToken<List<MenigaTransaction>>() {
}.getType());
} else {
MenigaTransaction updated = gson.fromJson(json.getAsJsonObject("data"), new TypeToken<MenigaTransaction>() {
}.getType());
updatedTransactions.add(updated);
}
List<MenigaTransaction> transactions = new ArrayList<>();
if (json.has("meta")) {
transactions = gson.fromJson(json.getAsJsonArray("meta"), new TypeToken<List<MenigaTransaction>>() {
}.getType());
}
return MenigaTransactionUpdate.fromList(updatedTransactions, transactions);
} finally {
if (isr != null) {
isr.close();
}
}
}
};
}
return null;
}
Aggregations