HtmlSerializerMiddlewares { public static <T> Middleware<AsyncHandler<T>, AsyncHandler<Response<ByteString>>> htmlSerialize( final String templateName) { return handler -> requestContext -> handler.invoke(requestContext) .thenApply(result -> Response .forPayload(serialize(templateName, result)) .withHeader(CONTENT_TYPE, HTML)); } private  HtmlSerializerMiddlewares(); static ByteString serialize(final String templateName, T object); static Middleware<AsyncHandler<T>, AsyncHandler<Response<ByteString>>> htmlSerialize(
      final String templateName); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<ByteString>>> htmlSerializeResponse(final String templateName); static Middleware<SyncHandler<T>, AsyncHandler<Response<ByteString>>> htmlSerializeSync(
      final String templateName); static Middleware<SyncHandler<Response<T>>, AsyncHandler<Response<ByteString>>> htmlSerializeResponseSync(
      final String templateName);  }
@Test public void testHtmlSerialize() throws Exception { Response<ByteString> response = Route.sync("GET", "/foo", rq -> ImmutableMap.of("match", "yo")) .withMiddleware(HtmlSerializerMiddlewares.htmlSerialize(TEST_TEMPLATE_FTL)) .handler().invoke(null).toCompletableFuture().get(); checkContentTypeAndBody(response); }