Skip to content

Commit

Permalink
Take application provided JSON providers when warning about missing J…
Browse files Browse the repository at this point in the history
…SON feature

Fixes: #28195
  • Loading branch information
geoand committed Sep 27, 2022
1 parent 73ee079 commit 2e21ad0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.common.ResteasyReactiveConfig;
import org.jboss.resteasy.reactive.common.processor.DefaultProducesHandler;
import org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveScanner;
import org.jboss.resteasy.reactive.common.processor.scanning.ScannedSerializer;
import org.jboss.resteasy.reactive.common.processor.scanning.SerializerScanningResult;
import org.jboss.resteasy.reactive.common.processor.transformation.AnnotationStore;
import org.jboss.resteasy.reactive.server.model.ServerResourceMethod;
import org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer;
Expand Down Expand Up @@ -43,6 +46,7 @@ public class QuarkusServerEndpointIndexer
private final ResteasyReactiveRecorder resteasyReactiveRecorder;

private final Predicate<String> applicationClassPredicate;
private SerializerScanningResult serializerScanningResult;

QuarkusServerEndpointIndexer(Builder builder) {
super(builder);
Expand Down Expand Up @@ -170,10 +174,33 @@ private void warnAboutMissingJsonProviderIfNeeded(ServerResourceMethod method, M
return;
}
if (hasJson(method) || (hasNoTypesDefined(method) && isDefaultJson())) {
LOGGER.warnf("Quarkus detected the use of JSON in JAX-RS method '" + info.declaringClass().name() + "#"
+ info.name()
+ "' but no JSON extension has been added. Consider adding 'quarkus-resteasy-reactive-jackson' or 'quarkus-resteasy-reactive-jsonb'.");
if (serializerScanningResult == null) {
serializerScanningResult = ResteasyReactiveScanner.scanForSerializers(index, applicationScanningResult);
}
boolean appProvidedJsonReaderExists = appProvidedJsonProviderExists(serializerScanningResult.getReaders());
boolean appProvidedJsonWriterExists = appProvidedJsonProviderExists(serializerScanningResult.getWriters());
if (!appProvidedJsonReaderExists || !appProvidedJsonWriterExists) {
LOGGER.warnf("Quarkus detected the use of JSON in JAX-RS method '" + info.declaringClass().name() + "#"
+ info.name()
+ "' but no JSON extension has been added. Consider adding 'quarkus-resteasy-reactive-jackson' or 'quarkus-resteasy-reactive-jsonb'.");
}
}
}

private boolean appProvidedJsonProviderExists(List<ScannedSerializer> providers) {
boolean appProvidedJsonReaderExists = false;
for (ScannedSerializer provider : providers) {
for (String mt : provider.getMediaTypeStrings()) {
if (isJson(mt)) {
appProvidedJsonReaderExists = true;
break;
}
}
if (appProvidedJsonReaderExists) {
break;
}
}
return appProvidedJsonReaderExists;
}

private boolean isDefaultJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public abstract class EndpointIndexer<T extends EndpointIndexer<T, PARAM, METHOD
private final Function<String, BeanFactory<Object>> factoryCreator;
private final Consumer<ResourceMethodCallbackData> resourceMethodCallback;
private final AnnotationStore annotationStore;
private final ApplicationScanningResult applicationScanningResult;
protected final ApplicationScanningResult applicationScanningResult;
private final Set<DotName> contextTypes;
private final MultipartReturnTypeIndexerExtension multipartReturnTypeIndexerExtension;
private final MultipartParameterIndexerExtension multipartParameterIndexerExtension;
Expand Down

0 comments on commit 2e21ad0

Please sign in to comment.