diff --git a/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java b/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java index 4473273519dd4..0d44455ea089c 100644 --- a/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java +++ b/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java @@ -96,6 +96,8 @@ public class ResteasyCommonProcessor { private static final DotName QUARKUS_JSONB_SERIALIZER = DotName .createSimple("io.quarkus.resteasy.common.runtime.jsonb.QuarkusJsonbSerializer"); + private static final String APPLICATION_HAL_JSON = "application/hal+json"; + private static final String[] WILDCARD_MEDIA_TYPE_ARRAY = { MediaType.WILDCARD }; private ResteasyCommonConfig resteasyCommonConfig; @@ -217,7 +219,8 @@ JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer mediaTypes = Collections.emptyList(); + List foundMediaTypes = Collections.emptyList(); if (annotationValue.kind() == Kind.ARRAY) { - mediaTypes = Arrays.asList(annotationValue.asStringArray()); + foundMediaTypes = Arrays.asList(annotationValue.asStringArray()); } else if (annotationValue.kind() == Kind.STRING) { - mediaTypes = Collections.singletonList(annotationValue.asString()); + foundMediaTypes = Collections.singletonList(annotationValue.asString()); + } + + for (int i = 0; i < mediaTypes.length; i++) { + if (foundMediaTypes.contains(mediaTypes[i])) { + return true; + } } - return mediaTypes.contains(MediaType.APPLICATION_JSON) - || mediaTypes.contains(MediaType.APPLICATION_JSON_PATCH_JSON); } return false; diff --git a/extensions/resteasy-classic/resteasy-links/deployment/src/main/java/io/quarkus/resteasy/links/deployment/LinksProcessor.java b/extensions/resteasy-classic/resteasy-links/deployment/src/main/java/io/quarkus/resteasy/links/deployment/LinksProcessor.java index f972525e283e3..7829b37caae56 100644 --- a/extensions/resteasy-classic/resteasy-links/deployment/src/main/java/io/quarkus/resteasy/links/deployment/LinksProcessor.java +++ b/extensions/resteasy-classic/resteasy-links/deployment/src/main/java/io/quarkus/resteasy/links/deployment/LinksProcessor.java @@ -15,12 +15,6 @@ void addHalSupport(Capabilities capabilities, BuildProducer additionalBeans) { boolean isHalSupported = capabilities.isPresent(Capability.HAL); if (isHalSupported) { - if (!capabilities.isPresent(Capability.RESTEASY_JSON_JSONB) - && !capabilities.isPresent(Capability.RESTEASY_JSON_JACKSON)) { - throw new IllegalStateException("Cannot generate HAL endpoints without " - + "either 'quarkus-resteasy-jsonb' or 'quarkus-resteasy-jackson'"); - } - jaxRsProviders.produce( new ResteasyJaxrsProviderBuildItem(HalServerResponseFilter.class.getName())); diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksProcessor.java index 939dfdb14d2a0..2cdbfff1adc09 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksProcessor.java @@ -14,6 +14,7 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; import org.jboss.jandex.IndexView; +import org.jboss.resteasy.reactive.common.util.RestMediaType; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.deployment.Capabilities; @@ -82,16 +83,25 @@ AdditionalBeanBuildItem registerRestLinksProviderProducer() { } @BuildStep - void addHalSupport(Capabilities capabilities, BuildProducer customResponseFilters, - BuildProducer additionalBeans) { + void validateJsonNeededForHal(Capabilities capabilities, + ResteasyReactiveResourceMethodEntriesBuildItem resourceMethodEntriesBuildItem) { boolean isHalSupported = capabilities.isPresent(Capability.HAL); - if (isHalSupported) { + if (isHalSupported && isHalMediaTypeUsedInAnyResource(resourceMethodEntriesBuildItem.getEntries())) { + if (!capabilities.isPresent(Capability.RESTEASY_REACTIVE_JSON_JSONB) && !capabilities.isPresent( Capability.RESTEASY_REACTIVE_JSON_JACKSON)) { throw new IllegalStateException("Cannot generate HAL endpoints without " + "either 'quarkus-resteasy-reactive-jsonb' or 'quarkus-resteasy-reactive-jackson'"); } + } + } + @BuildStep + void addHalSupport(Capabilities capabilities, + BuildProducer customResponseFilters, + BuildProducer additionalBeans) { + boolean isHalSupported = capabilities.isPresent(Capability.HAL); + if (isHalSupported) { customResponseFilters.produce( new CustomContainerResponseFilterBuildItem(HalServerResponseFilter.class.getName())); @@ -99,6 +109,18 @@ void addHalSupport(Capabilities capabilities, BuildProducer entries) { + for (ResteasyReactiveResourceMethodEntriesBuildItem.Entry entry : entries) { + for (String mediaType : entry.getResourceMethod().getProduces()) { + if (RestMediaType.APPLICATION_HAL_JSON.equals(mediaType)) { + return true; + } + } + } + + return false; + } + private LinksContainer getLinksContainer(ResteasyReactiveResourceMethodEntriesBuildItem resourceMethodEntriesBuildItem, IndexView index) { LinksContainerFactory linksContainerFactory = new LinksContainerFactory();