0

I am converting the response body from a webclient call to a specific type in case of errors.

        if (clientResponse.statusCode().is4xxClientError() ||
                clientResponse.statusCode().is5xxServerError()) {

            return clientResponse.bodyToMono(ErrorDetails.class)
                         .map(e -> log.error("Response status: {}, error: {}", clientResponse.statusCode(), e);

In case of a response payload that cannot be deserialized to this type (ErrorDetails.class) because of a different json structure that expected, i am receiving an initialized object of the type specified in the map method. No error signal is generated.

Response status: 404 NOT_FOUND, error: class Error {\n    messages: null\n}

Is there a way to change this behavior's and request an error signal in case the response body cannot be set to the type specified?

ankush
  • 167
  • 1
  • 11
  • You can enforce validation for your POJO making some fields required https://stackoverflow.com/a/23133086/9068895 or just add validation step after deserialization and return error explicitly – Alex Dec 13 '22 at 01:01

0 Answers0