Skip to content

Commit

Permalink
Properly segregate Json MessageBodyReader/Writer classes for server a…
Browse files Browse the repository at this point in the history
…nd client

Fixes: quarkusio#30089
  • Loading branch information
geoand committed Jan 3, 2023
1 parent 533f315 commit c96c287
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.List;

import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.common.util.RestMediaType;
Expand All @@ -29,33 +30,37 @@ public class ResteasyReactiveJsonbCommonProcessor {
VertxJson.JsonArrayDeserializer.class.getName());

@BuildStep
void additionalProviders(BuildProducer<AdditionalBeanBuildItem> additionalBean,
BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
public void registerVertxJsonSupport(
BuildProducer<JsonbSerializerBuildItem> serializers,
BuildProducer<JsonbDeserializerBuildItem> deserializers) {
serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS));
deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS));
}

@BuildStep
public void beans(BuildProducer<AdditionalBeanBuildItem> additionalBean) {
// make these beans to they can get instantiated with the Quarkus CDI configured Jsonb object
additionalBean.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(JsonbMessageBodyReader.class.getName())
.addBeanClass(JsonbMessageBodyWriter.class.getName())
.setUnremovable().build());
}

public static void additionalProviders(BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters, RuntimeType runtimeType) {

additionalReaders.produce(
new MessageBodyReaderBuildItem.Builder(JsonbMessageBodyReader.class.getName(), Object.class.getName())
.setMediaTypeStrings(Collections.singletonList(MediaType.APPLICATION_JSON))
.setBuiltin(true)
.setRuntimeType(runtimeType)
.build());
additionalWriters.produce(
new MessageBodyWriterBuildItem.Builder(JsonbMessageBodyWriter.class.getName(), Object.class.getName())
.setMediaTypeStrings(List.of(MediaType.APPLICATION_JSON, RestMediaType.APPLICATION_NDJSON,
RestMediaType.APPLICATION_STREAM_JSON))
.setBuiltin(true)
.setRuntimeType(runtimeType)
.build());
}

@BuildStep
public void registerVertxJsonSupport(
BuildProducer<JsonbSerializerBuildItem> serializers,
BuildProducer<JsonbDeserializerBuildItem> deserializers) {
serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS));
deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.resteasy.reactive.common.deployment.ServerDefaultProducesHandlerBuildItem;
import io.quarkus.resteasy.reactive.jsonb.common.deployment.ResteasyReactiveJsonbCommonProcessor;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import javax.ws.rs.RuntimeType;

public class ResteasyReactiveJsonbProcessor {

Expand All @@ -17,4 +21,11 @@ void feature(BuildProducer<FeatureBuildItem> feature) {
ServerDefaultProducesHandlerBuildItem jsonDefault() {
return ServerDefaultProducesHandlerBuildItem.json();
}

@BuildStep
void additionalProviders(BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters,
RuntimeType.SERVER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

import static io.quarkus.deployment.Feature.REST_CLIENT_REACTIVE_JSONB;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.resteasy.reactive.jsonb.common.deployment.ResteasyReactiveJsonbCommonProcessor;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import java.util.Collections;
import java.util.List;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.reactive.common.util.RestMediaType;
import org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader;
import org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyWriter;

public class RestClientReactiveJsonbProcessor {

@BuildStep
void feature(BuildProducer<FeatureBuildItem> features) {
features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JSONB));
}

@BuildStep
void additionalProviders(BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters,
RuntimeType.CLIENT);
}
}

0 comments on commit c96c287

Please sign in to comment.