无法识别的标记 'Payment':期待(JSON 字符串、数字、数组、对象或标记 'null'、'true' 或 'false')
Unrecognized token 'Payment': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
我正在开发两个 Spring 使用 H2 数据库的引导微服务(订单和支付) 订单微服务通过 RestTemplate
调用支付服务 每当我使用邮递员预订订单时,支付服务都会被成功调用并且数据存储在支付数据库中,但不在订单服务中,我收到上述错误:
这是我的代码
服务
public TransactionResponse saveOrder(TransactionRequest request) {
String responseMessage = "";
Order order = request.getOrder();
Payment payment = request.getPayment();
payment.setOrderId(order.getId());
payment.setAmount(order.getPrice());
// response message
System.out.println(order);
// rest api call to payment service
Payment paymentResponse =
restTemplate.postForObject("http://localhost:8082/api/payment", payment, Payment.class);
responseMessage = paymentResponse.getPaymentStatus().equals("success")?
"payment processed successfully": "payment failed ";
orderRepository.save(order);
System.out.println(paymentResponse);
return new TransactionResponse(order , paymentResponse.getTransactionId() , paymentResponse.getAmount(), responseMessage);
}
控制器
@PostMapping
public TransactionResponse bookOrder(@RequestBody TransactionRequest transactionRequest) {
return orderService.saveOrder(transactionRequest);
}
事务请求模型
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TransactionRequest {
private Order order;
private Payment payment;
}
支付模式
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment {
private int paymentId;
private String paymentStatus;
private String transactionId;
private double amount;
private int orderId;
}
图片
哦,我遇到了问题,因为我正在休息 api 调用支付服务,支付服务的 post 方法是 returning 字符串而不是支付对象。
这是我之前的post付款方式:
@PostMapping
public String orderPayment(@RequestBody Payment payment) {
paymentService.doPayment(payment);
return "Payment done";
}
这就是应该的样子
@PostMapping
public Payment orderPayment(@RequestBody Payment payment) {
return paymentService.doPayment(payment);
}
注意:return 类型
我正在开发两个 Spring 使用 H2 数据库的引导微服务(订单和支付) 订单微服务通过 RestTemplate
调用支付服务 每当我使用邮递员预订订单时,支付服务都会被成功调用并且数据存储在支付数据库中,但不在订单服务中,我收到上述错误:
这是我的代码
服务
public TransactionResponse saveOrder(TransactionRequest request) {
String responseMessage = "";
Order order = request.getOrder();
Payment payment = request.getPayment();
payment.setOrderId(order.getId());
payment.setAmount(order.getPrice());
// response message
System.out.println(order);
// rest api call to payment service
Payment paymentResponse =
restTemplate.postForObject("http://localhost:8082/api/payment", payment, Payment.class);
responseMessage = paymentResponse.getPaymentStatus().equals("success")?
"payment processed successfully": "payment failed ";
orderRepository.save(order);
System.out.println(paymentResponse);
return new TransactionResponse(order , paymentResponse.getTransactionId() , paymentResponse.getAmount(), responseMessage);
}
控制器
@PostMapping
public TransactionResponse bookOrder(@RequestBody TransactionRequest transactionRequest) {
return orderService.saveOrder(transactionRequest);
}
事务请求模型
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TransactionRequest {
private Order order;
private Payment payment;
}
支付模式
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment {
private int paymentId;
private String paymentStatus;
private String transactionId;
private double amount;
private int orderId;
}
图片
哦,我遇到了问题,因为我正在休息 api 调用支付服务,支付服务的 post 方法是 returning 字符串而不是支付对象。
这是我之前的post付款方式:
@PostMapping
public String orderPayment(@RequestBody Payment payment) {
paymentService.doPayment(payment);
return "Payment done";
}
这就是应该的样子
@PostMapping
public Payment orderPayment(@RequestBody Payment payment) {
return paymentService.doPayment(payment);
}
注意:return 类型