use of com.meniga.sdk.models.transactions.MenigaTransaction 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;
}
use of com.meniga.sdk.models.transactions.MenigaTransaction in project mobile-sdk-android by meniga.
the class MenigaTransactionOperationsMock method gson.
private MenigaTransactionPage gson() {
Gson gson = GsonProvider.getGsonBuilder();
MenigaTransactionPage transactionPage = null;
try {
InputStream inputStream = FileImporter.getInputStreamFromRaw("transactions.json");
MenigaTransaction[] arr = gson.fromJson(MenigaConverter.getAsArray(inputStream), MenigaTransaction[].class);
transactionPage = new MenigaTransactionPage();
transactionPage.addAll(Arrays.asList(arr));
} catch (IOException e) {
e.printStackTrace();
}
return transactionPage;
}
Aggregations