diff --git a/pom.xml b/pom.xml
index 28d056de0..65203ff28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.hateoas
spring-hateoas
- 1.1.0.BUILD-SNAPSHOT
+ 1.1.0.HATEOAS-1060-SNAPSHOT
Spring HATEOAS
https://github.com/spring-projects/spring-hateoas
diff --git a/src/main/java/org/springframework/hateoas/config/EnableHypermediaSupport.java b/src/main/java/org/springframework/hateoas/config/EnableHypermediaSupport.java
index c333bed51..0eb4bc606 100644
--- a/src/main/java/org/springframework/hateoas/config/EnableHypermediaSupport.java
+++ b/src/main/java/org/springframework/hateoas/config/EnableHypermediaSupport.java
@@ -44,11 +44,12 @@
public @interface EnableHypermediaSupport {
/**
- * The hypermedia type to be supported.
+ * The hypermedia type to be supported. By default, it is empty, thus activating all available
+ * {@link MediaTypeConfigurationProvider}s.
*
* @return
*/
- HypermediaType[] type();
+ HypermediaType[] type() default {};
/**
* Configures which {@link WebStack}s we're supposed to enable support for. By default we're activating it for all
diff --git a/src/main/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelector.java b/src/main/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelector.java
index d868296dd..06615dd95 100644
--- a/src/main/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelector.java
+++ b/src/main/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelector.java
@@ -71,9 +71,9 @@ public String[] selectImports(AnnotationMetadata metadata) {
List configurationProviders = SpringFactoriesLoader.loadFactories(
MediaTypeConfigurationProvider.class, HypermediaConfigurationImportSelector.class.getClassLoader());
- // Filter the ones supporting the given media types
+ // Filter the ones supporting the given media types, or let them all through if none declared.
Stream imports = configurationProviders.stream() //
- .filter(it -> it.supportsAny(types)) //
+ .filter(it -> types.isEmpty() || it.supportsAny(types)) //
.map(MediaTypeConfigurationProvider::getConfiguration) //
.map(Class::getName);
diff --git a/src/test/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelectorUnitTest.java b/src/test/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelectorUnitTest.java
index 0a38d0a53..42d4a71d8 100644
--- a/src/test/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelectorUnitTest.java
+++ b/src/test/java/org/springframework/hateoas/config/HypermediaConfigurationImportSelectorUnitTest.java
@@ -118,6 +118,22 @@ void doesNotIncludeWebTestHateoasConfigurationIfWebTestClientIsNotOnTheClasspath
}, loader);
}
+ @Test // #1060
+ void testEmptyHypermediaTypes() {
+
+ withContext(NoConfig.class, context -> {
+
+ Map linkDiscoverers = context.getBeansOfType(LinkDiscoverer.class);
+
+ assertThat(linkDiscoverers.values()).extracting("class") //
+ .containsExactlyInAnyOrder( //
+ HalLinkDiscoverer.class, //
+ HalFormsLinkDiscoverer.class, //
+ UberLinkDiscoverer.class, //
+ CollectionJsonLinkDiscoverer.class);
+ });
+ }
+
@EnableHypermediaSupport(type = HAL)
static class HalConfig {
@@ -137,4 +153,9 @@ static class HalAndHalFormsConfig {
static class AllConfig {
}
+
+ @EnableHypermediaSupport
+ static class NoConfig {
+
+ }
}
diff --git a/src/test/java/org/springframework/hateoas/support/CustomHypermediaConfigurationProvider.java b/src/test/java/org/springframework/hateoas/support/CustomHypermediaConfigurationProvider.java
new file mode 100644
index 000000000..7e0295dcd
--- /dev/null
+++ b/src/test/java/org/springframework/hateoas/support/CustomHypermediaConfigurationProvider.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.hateoas.support;
+
+import java.util.Collection;
+
+import org.springframework.hateoas.config.HypermediaMappingInformation;
+import org.springframework.hateoas.config.MediaTypeConfigurationProvider;
+import org.springframework.http.MediaType;
+
+/**
+ * @author Greg Turnquist
+ */
+public class CustomHypermediaConfigurationProvider implements MediaTypeConfigurationProvider {
+
+ @Override
+ public Class extends HypermediaMappingInformation> getConfiguration() {
+ return CustomHypermediaType.class;
+ }
+
+ @Override
+ public boolean supportsAny(Collection mediaTypes) {
+ return mediaTypes.stream().anyMatch(mediaType -> mediaType.isCompatibleWith(CustomHypermediaType.FRODO_MEDIATYPE));
+ }
+}
diff --git a/src/test/resources/META-INF/spring.factories b/src/test/resources/META-INF/spring.factories
new file mode 100644
index 000000000..5bbbf9f27
--- /dev/null
+++ b/src/test/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.hateoas.config.MediaTypeConfigurationProvider=\
+ org.springframework.hateoas.support.CustomHypermediaConfigurationProvider