Repository: quarkusio/quarkus
Issue: OutboundSseEvent is not correctly serialized

**Describe the bug**

When creating a `OutboundSseEvent` object and returning it back in a REST Endpoint it is not correctly serialized.

**Expected behavior**

`Server-Side Event` is sent back and it is able to be deserialized correctly.

**Actual behavior**

Either an exception that the object cannot be serialized or in case of using 

```
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.SERVER_SENT_EVENTS)
```

Then all properties like `name`, `data`, `comment` ... are serialized as a data and not in the correct fields.


**To Reproduce**
Steps to reproduce the behavior:

Repo is here: https://github.com/lordofthejars/quarkus-quartz-streams

1.  Run https://github.com/lordofthejars/quarkus-quartz-streams/blob/master/src/test/java/org/acme/ExampleResourceTest.java

**Environment (please complete the following information):**

 - Quarkus 1.6.0.Final

Changed files:
extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamTestCase.java
independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java
extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamResource.java

diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamResource.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamResource.java
index def237ac8da..307d5b77d5d 100644
--- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamResource.java
+++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamResource.java
@@ -8,7 +8,10 @@
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.sse.OutboundSseEvent;
+import javax.ws.rs.sse.Sse;
 
 import org.jboss.resteasy.reactive.common.util.MultiCollectors;
 import org.reactivestreams.Publisher;
@@ -152,4 +155,13 @@ public Multi<String> sse() {
     public Multi<String> sseThrows() {
         throw new IllegalStateException("STOP");
     }
+
+    @Path("sse/raw")
+    @GET
+    @Produces(MediaType.SERVER_SENT_EVENTS)
+    public Multi<OutboundSseEvent> sseRaw(@Context Sse sse) {
+        return Multi.createFrom().items(sse.newEventBuilder().id("one").data("uno").name("eins").build(),
+                sse.newEventBuilder().id("two").data("dos").name("zwei").build(),
+                sse.newEventBuilder().id("three").data("tres").name("drei").build());
+    }
 }
diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamTestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamTestCase.java
index 36df4075e76..d43b1ddb124 100644
--- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamTestCase.java
+++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/stream/StreamTestCase.java
@@ -237,4 +237,32 @@ public void testSseThrows() throws InterruptedException {
             Assertions.assertEquals(1, errors.size());
         }
     }
+
+    @Test
+    public void testSseForMultiWithOutboundSseEvent() throws InterruptedException {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget target = client.target(this.uri.toString() + "stream/sse/raw");
+        try (SseEventSource sse = SseEventSource.target(target).build()) {
+            CountDownLatch latch = new CountDownLatch(1);
+            List<Throwable> errors = new CopyOnWriteArrayList<>();
+            List<String> results = new CopyOnWriteArrayList<>();
+            List<String> ids = new CopyOnWriteArrayList<>();
+            List<String> names = new CopyOnWriteArrayList<>();
+            sse.register(event -> {
+                results.add(event.readData());
+                ids.add(event.getId());
+                names.add(event.getName());
+            }, error -> {
+                errors.add(error);
+            }, () -> {
+                latch.countDown();
+            });
+            sse.open();
+            Assertions.assertTrue(latch.await(20, TimeUnit.SECONDS));
+            Assertions.assertEquals(Arrays.asList("uno", "dos", "tres"), results);
+            Assertions.assertEquals(Arrays.asList("one", "two", "three"), ids);
+            Assertions.assertEquals(Arrays.asList("eins", "zwei", "drei"), names);
+            Assertions.assertEquals(0, errors.size());
+        }
+    }
 }
diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java
index 3ac1f35a6de..45389d6c2ca 100644
--- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java
+++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java
@@ -11,6 +11,7 @@
 import java.util.function.Consumer;
 
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.sse.OutboundSseEvent;
 
 import org.jboss.logging.Logger;
 import org.jboss.resteasy.reactive.common.util.RestMediaType;
@@ -49,7 +50,12 @@ private static class SseMultiSubscriber extends AbstractMultiSubscriber {
 
         @Override
         public void onNext(Object item) {
-            OutboundSseEventImpl event = new OutboundSseEventImpl.BuilderImpl().data(item).build();
+            OutboundSseEvent event;
+            if (item instanceof OutboundSseEvent) {
+                event = (OutboundSseEvent) item;
+            } else {
+                event = new OutboundSseEventImpl.BuilderImpl().data(item).build();
+            }
             SseUtil.send(requestContext, event, customizers).whenComplete(new BiConsumer<Object, Throwable>() {
                 @Override
                 public void accept(Object v, Throwable t) {