Source:
Mono<Response<?>> invoke(final Constructor<? extends Response<?>> constructor, final HttpResponseDecoder.HttpDecodedResponse decodedResponse, final Object bodyAsObject) { final HttpResponse httpResponse = decodedResponse.getSourceResponse(); final HttpRequest httpRequest = httpResponse.getRequest(); final int responseStatusCode = httpResponse.getStatusCode(); final HttpHeaders responseHeaders = httpResponse.getHeaders(); final int paramCount = constructor.getParameterCount(); switch (paramCount) { case 3: try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 3-parameter " + "response. Error Details: " + e.getMessage(), e)); } case 4: try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 4-parameter " + "response. Error Details: " + e.getMessage(), e)); } case 5: return decodedResponse.getDecodedHeaders() .map((Function<Object, Response<?>>) decodedHeaders -> { try { return constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject, decodedHeaders); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 5-parameter" + "response with decoded headers. Error Details: " + e.getMessage(), e)); } }) .switchIfEmpty(Mono.defer((Supplier<Mono<Response<?>>>) () -> { try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject, null)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 5-parameter" + "response without decoded headers. Error Details: " + e.getMessage(), e)); } })); default: throw logger.logExceptionAsError( new IllegalStateException("Response constructor with expected parameters not found.")); } }

Target:
Mono<Response<?>> invoke(final Constructor<? extends Response<?>> constructor, final HttpResponseDecoder.HttpDecodedResponse decodedResponse, final Object bodyAsObject) { final HttpResponse httpResponse = decodedResponse.getSourceResponse(); final HttpRequest httpRequest = httpResponse.getRequest(); final int responseStatusCode = httpResponse.getStatusCode(); final HttpHeaders responseHeaders = httpResponse.getHeaders(); final int paramCount = constructor.getParameterCount(); switch (paramCount) { case 3: try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 3-parameter" + " response. ", e)); } case 4: try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 4-parameter" + " response. ", e)); } case 5: return decodedResponse.getDecodedHeaders() .map((Function<Object, Response<?>>) decodedHeaders -> { try { return constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject, decodedHeaders); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException("Failed to deserialize 5-parameter" + " response with decoded headers. ", e)); } }) .switchIfEmpty(Mono.defer((Supplier<Mono<Response<?>>>) () -> { try { return Mono.just(constructor.newInstance(httpRequest, responseStatusCode, responseHeaders, bodyAsObject, null)); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw logger.logExceptionAsError(new RuntimeException( "Failed to deserialize 5-parameter response without decoded headers.", e)); } })); default: throw logger.logExceptionAsError( new IllegalStateException("Response constructor with expected parameters not found.")); } }