Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take application provided JSON providers when warning about missing JSON feature #28223

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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