反序列化 BankAccount 对象时条纹 InvalidDefinitionException - Java
Stripe InvalidDefinitionException when deserializing BankAccount object - Java
简而言之,我有一个 Stripe bank account object,我正在尝试 return 到 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);
如何将这个银行账户对象发送回前端,可能是 Hashmap 或其他 JSON 格式的对象。
我不断收到以下错误:
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"])]
我建议改用 ID,但应该可以从任何 Stripe 对象 (source) 中获取 JSON 对象,然后您可以 serialize/parse 作为你觉得合适。
我只需附加 toJson()
就可以解决问题:
payload.put("payment", bankaccount.toJson());
缺点是前端需要额外的 JSON.parse()
简而言之,我有一个 Stripe bank account object,我正在尝试 return 到 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);
如何将这个银行账户对象发送回前端,可能是 Hashmap 或其他 JSON 格式的对象。
我不断收到以下错误:
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"])]
我建议改用 ID,但应该可以从任何 Stripe 对象 (source) 中获取 JSON 对象,然后您可以 serialize/parse 作为你觉得合适。
我只需附加 toJson()
就可以解决问题:
payload.put("payment", bankaccount.toJson());
缺点是前端需要额外的 JSON.parse()