NormalizationMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { @Override public HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain) { Parameters params = request.getParams(); if (params != null) { params.keySet().forEach(key -> { Object obj = params.getRawType(key); if (obj == null) return; normalizationSpecs.forEach(c -> { if (c.getPredicate().test(key) && c.getNormalizer().canNormalize(obj.getClass())) { params.replace(key, c.getNormalizer().normalize(obj)); } }); }); } return castToHttpResponse(chain.next(request)); } NormalizationMiddleware();  NormalizationMiddleware(NormalizationSpec<Object> spec, NormalizationSpec<Object>... specs); static NormalizationSpec<T> normalization(Predicate<String> predicate, Normalizer<T> normalizer); @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain);  }
@Test void noNormalization() { NormalizationMiddleware<HttpResponse> middleware = new NormalizationMiddleware<>(); HttpRequest request = new DefaultHttpRequest(); request.setParams(Parameters.of("A", "B", "C", 1)); MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(Predicates.any(), "endpoint", (req, c) -> builder(HttpResponse.of("dummy")) .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/plain")) .build()); middleware.handle(request, chain); assertThat(request.getParams()) .containsExactly(entry("A", "B"), entry("C", 1)); }