Answer the question
In order to leave comments, you need to log in
How to parse json array using web client?
Good evening!
I have a server, referring to which I get a json array:
[
{
"idTxn": ****
"idPayer": *****,
"idPayee": ****,
"idTxnStatus": 30,
"idErrorCode": 0,
"errorDescription": "OK",
"rbsId": "480021286",
"mbStatus": "prinyata",
"purposeOfPayment": " ",
"datCreation": "2021-12-12 10:02:51.016",
"amount": 50,
"attributes": [],
"useCase": "Перевод"
},
{
"idTxn": ***,
"idPayer": ***,
"idPayee": ******,
"idTxnStatus": 30,
"idErrorCode": 0,
"errorDescription": "OK",
"rbsId": "****",
"mbStatus": "prinyata",
"purposeOfPayment": "Pay Cash-In. Номер транзакции: ******.",
"datCreation": "2018-12-20 19:37:39.206",
"amount": 123,
"attributes": [
{
"name": " аттрибут :",
"value": "20"
}
],
"useCase": "Pudxc"
}
]
WebClient webClient = WebClient.create();
@GetMapping("/cash")
public String cashInInfo(@RequestParam(value = "phone") String phone, Model model) {
try {
List<CashInInfo> info =
Collections.singletonList(webClient.post()
.uri(get_cash_in + "?limit=1&type=cash-in&phone=" + phone)
.retrieve()
.bodyToMono(CashInInfo.class)
.block());
log.info("cash-in result : {}", info);
System.out.println(info);
System.out.println(Arrays.toString(new List[]{info}));
} catch (WebClientException e) {
model.addAttribute("cash_in_not_found", "cash-in не найден");
log.error("something wrong into the webClient: {}", e.getMessage());
}
return "last_cash";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question