JsonSerializerMiddlewares { public static <T> Middleware<SyncHandler<Response<T>>, AsyncHandler<Response<ByteString>>> jsonSerializeResponseSync(ObjectWriter objectWriter) { Middleware<SyncHandler<Response<T>>, AsyncHandler<Response<T>>> syncToAsync = Middleware::syncToAsync; return syncToAsync.and(jsonSerializeResponse(objectWriter)); } private  JsonSerializerMiddlewares(); static Middleware<AsyncHandler<T>, AsyncHandler<Response<ByteString>>> jsonSerialize(ObjectWriter objectWriter); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<ByteString>>> jsonSerializeResponse(ObjectWriter objectWriter); static Middleware<SyncHandler<T>, AsyncHandler<Response<ByteString>>> jsonSerializeSync(ObjectWriter objectWriter); static Middleware<SyncHandler<Response<T>>, AsyncHandler<Response<ByteString>>> jsonSerializeResponseSync(ObjectWriter objectWriter);  }
@Test public void shouldJsonSerializeResponseSync() throws Exception { Middleware<SyncHandler<Response<TestBean>>, AsyncHandler<Response<ByteString>>> sync = JsonSerializerMiddlewares.jsonSerializeResponseSync(WRITER); Response<ByteString> response = sync.apply( rq -> Response.forStatus(Status.CONFLICT).withPayload(new TestBean())) .invoke(null).toCompletableFuture().get(); checkPayloadAndContentType(response); assertThat(response.status(), equalTo(Status.CONFLICT)); }