I am using Springs' Webclient to make a HTTP GET call.
How can I validate the response object GetPersonBasicInfoResWrapper's property that I received as a response of my HTTP call.
I am trying to validate the birthDate inside the flatMap by blocking the response object, but it doesn't look like the most functional way of doing it.
Following is the excerpt from my code.
private Mono<GetPersonBasicInfoResWrapper> getPersonBasicInfo(Double personId, LocalDate birthDate,
CallerRequestMetaData callerInfo) {
return middlewareWebClient
.get()
.uri(...)
...
...
.exchange()
.flatMap(client -> {
GetPersonBasicInfoResWrapper block = client.bodyToMono(GetPersonBasicInfoResWrapper.class).block();
LocalDate personBirthDate = LocalDateTime.ofInstant(block.getBirthDate().toInstant(),ZoneId.of(Constants.DEFAULT_TIME_ZOME)).toLocalDate();
if (!personBirthDate.equals(birthDate))
throw new YakeenRowadException(Errors.INCORRECT_ID_BIRTH_DATE_G, birthDate.toString());
else
return client.bodyToMono(GetPersonBasicInfoResWrapper.class);
});
}
Any help is highly appreciated.