diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java index 2a2377cc3e021..705d96fcef9d7 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java @@ -198,16 +198,19 @@ public static boolean invokeWriter(ResteasyReactiveRequestContext context, Objec WriterInterceptor[] writerInterceptors = context.getWriterInterceptors(); boolean outputStreamSet = context.getOutputStream() != null; context.serverResponse().setPreCommitListener(HEADER_FUNCTION); + + RuntimeResource target = context.getTarget(); + Type genericType; + if (context.hasGenericReturnType()) { // make sure that when a Response with a GenericEntity was returned, we use it + genericType = context.getGenericReturnType(); + } else { + genericType = target == null ? null : target.getReturnType(); + } + try { if (writer instanceof ServerMessageBodyWriter && writerInterceptors == null && !outputStreamSet) { ServerMessageBodyWriter quarkusRestWriter = (ServerMessageBodyWriter) writer; - RuntimeResource target = context.getTarget(); - Type genericType; - if (context.hasGenericReturnType()) { // make sure that when a Response with a GenericEntity was returned, we use it - genericType = context.getGenericReturnType(); - } else { - genericType = target == null ? null : target.getReturnType(); - } + Class entityClass = entity.getClass(); if (quarkusRestWriter.isWriteable( entityClass, @@ -230,7 +233,7 @@ public static boolean invokeWriter(ResteasyReactiveRequestContext context, Objec context.setResponseContentType(mediaType); } if (writerInterceptors == null) { - writer.writeTo(entity, entity.getClass(), context.getGenericReturnType(), + writer.writeTo(entity, entity.getClass(), genericType, context.getAllAnnotations(), context.getResponseMediaType(), response.getHeaders(), context.getOrCreateOutputStream()); context.getOrCreateOutputStream().close(); diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestResource.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestResource.java index 5570f23f853ee..86104b92e38aa 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestResource.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestResource.java @@ -233,6 +233,12 @@ public TestClass writer() { return new TestClass(); } + @GET + @Path("uni-writer") + public Uni uniWriter() { + return Uni.createFrom().item(new TestClass()); + } + @GET @Path("fast-writer") @Produces("text/plain") diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestTestCase.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestTestCase.java index 1324e5ca35a5a..1a3c0266a27ae 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestTestCase.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/SimpleQuarkusRestTestCase.java @@ -206,6 +206,8 @@ public void testWriter() { .then().body(Matchers.equalTo("OK")); RestAssured.get("/simple/writer") .then().body(Matchers.equalTo("WRITER")); + RestAssured.get("/simple/uni-writer") + .then().body(Matchers.equalTo("WRITER")); RestAssured.get("/simple/fast-writer") .then().body(Matchers.equalTo("OK")); diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/TestWriter.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/TestWriter.java index 18f8a2194846f..673f8dcdefd92 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/TestWriter.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/TestWriter.java @@ -26,7 +26,11 @@ public boolean isWriteable(Class type, Type genericType, Annotation[] annotat public void writeTo(TestClass t, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - entityStream.write("WRITER".getBytes(StandardCharsets.UTF_8)); + if (genericType.getTypeName().equals(TestClass.class.getName())) { + entityStream.write("WRITER".getBytes(StandardCharsets.UTF_8)); + } else { + entityStream.write("INCORRECT GENERIC TYPE".getBytes(StandardCharsets.UTF_8)); + } } }