我需要从第三方api接收来自webhook的请求。
文章内容是一个URL,格式如下:
event=invoice.created&数据%5bid%5d=value1&数据%5bstatus%5d=pending&数据%5baccount\u id%5d=value2
问题是用这些方括号序列化这个params data[id]。我在spring boot中遇到一个错误:
bean类[br.com.bettha.domain.dto.iuguwebhookdto]的无效属性“data[account\u id]”:索引属性路径“data[account\u id]”中引用的属性既不是数组,也不是列表,也不是Map;返回值为[iugudatadto(id=null,account\u id=null,status=null,subscription\u id=null)]
我的控制器:
@PostMapping(value = "/subscription-invoice", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
@ApiOperation(
value="Create a subscription invoice from Iugu's webhook",
response= Invoice.class,
notes="This Operation creates a subscription invoice from Iugu's webhook")
@PreAuthorize("#oauth2.hasScope('read')")
public ResponseEntity<Invoice> createSubscriptionInvoice(IuguWebhookDto iuguWebhookDto) {
try {
Invoice invoice = paymentService.createSubscriptionInvoiceFromIugusWebhook(iuguWebhookDto);
return new ResponseEntity<>(invoice, HttpStatus.CREATED);
} catch (EntityNotFoundException e) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage(), e);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
}
iuguwebhookdto.java文件:
@Getter
@Setter
@NoArgsConstructor
@ToString
public class IuguWebhookDto implements Serializable {
private static final long serialVersionUID = -5557936429069206933L;
private String event;
private IuguDataDto data;
iugudatadto.java文件:
@Getter
@Setter
@NoArgsConstructor
@ToString
public class IuguDataDto implements Serializable {
private static final long serialVersionUID = -5557936429069206933L;
private String id;
private String account_id;
private String status;
private String subscription_id;
如何在spring boot中作为对象接收这些请求参数?
暂无答案!
目前还没有任何答案,快来回答吧!