In short, I have a Stripe bank account object that I am trying to return to the client/front-end.
HashMap<String, Object> response = new HashMap<String, Object>();
HashMap<String, Object> payload = new HashMap<String, Object>();
HashMap<String, Object> retrieveParams = new HashMap<>();
List<String> expandList = new ArrayList<>();
expandList.add("sources");
retrieveParams.put("expand", expandList);
customer = Customer.retrieve("cus_JHnmRG1q0aI3wt", retrieveParams, null);
BankAccount bankaccount = (BankAccount) customer.getSources().retrieve(customer.getMetadata().get("source"));
payload.put("payment", bankaccount); /*** Creates Error***/
response.put("payload", payload);
return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
How can I send this bankaccount object back to the front-end, maybe a Hashmap or other JSON formatted object.
I keep getting the following error:
Type definition error: [simple type, class com.stripe.net.StripeResponse]; nested exception is
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class
com.stripe.net.StripeResponse and no properties discovered to create BeanSerializer (to avoid exception,
disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.HashMap["payload"]->
java.util.HashMap["payment"]->com.stripe.model.BankAccount["lastResponse"])]
I was able to solve the issue by just appending toJson()
as such:
payload.put("payment", bankaccount.toJson());
The downside to this is the additional JSON.parse()
required on the front-end