File tree 4 files changed +73
-4
lines changed
main/java/org/springframework/hateoas/config
java/org/springframework/hateoas
4 files changed +73
-4
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public String[] selectImports(AnnotationMetadata metadata) {
44
44
45
45
Map <String , Object > attributes = metadata .getAnnotationAttributes (EnableHypermediaSupport .class .getName ());
46
46
47
- List <MediaType > types = attributes == null //
47
+ List <MediaType > mediaTypes = attributes == null //
48
48
? Collections .emptyList () //
49
49
: Arrays .stream ((HypermediaType []) attributes .get ("type" )) //
50
50
.flatMap (it -> it .getMediaTypes ().stream ()) //
@@ -53,10 +53,18 @@ public String[] selectImports(AnnotationMetadata metadata) {
53
53
List <MediaTypeConfigurationProvider > configurationProviders = SpringFactoriesLoader .loadFactories (
54
54
MediaTypeConfigurationProvider .class , HypermediaConfigurationImportSelector .class .getClassLoader ());
55
55
56
- // Filter the ones supporting the given media types
57
56
return configurationProviders .stream () //
58
- .filter (it -> it .supportsAny (types )) //
59
- .map (MediaTypeConfigurationProvider ::getConfiguration ) //
57
+ .filter (it -> {
58
+ // If there are no types, then let them all through
59
+ if (mediaTypes .isEmpty ()) {
60
+ return true ;
61
+ }
62
+ // Filter the ones supporting the given media types
63
+ return it .supportsAny (mediaTypes );
64
+ }) //
65
+ .map ((MediaTypeConfigurationProvider mediaTypeConfigurationProvider ) -> {
66
+ return mediaTypeConfigurationProvider .getConfiguration ();
67
+ }) //
60
68
.map (Class ::getName ) //
61
69
.toArray (String []::new );
62
70
}
Original file line number Diff line number Diff line change @@ -89,6 +89,22 @@ void testAllImportConfigurations() {
89
89
});
90
90
}
91
91
92
+ @ Test // #1060
93
+ void testEmptyHypermediaTypes () {
94
+
95
+ withContext (NoConfig .class , context -> {
96
+
97
+ Map <String , LinkDiscoverer > linkDiscoverers = context .getBeansOfType (LinkDiscoverer .class );
98
+
99
+ assertThat (linkDiscoverers .values ()).extracting ("class" ) //
100
+ .containsExactlyInAnyOrder ( //
101
+ HalLinkDiscoverer .class , //
102
+ HalFormsLinkDiscoverer .class , //
103
+ UberLinkDiscoverer .class , //
104
+ CollectionJsonLinkDiscoverer .class );
105
+ });
106
+ }
107
+
92
108
@ EnableHypermediaSupport (type = HAL )
93
109
static class HalConfig {
94
110
@@ -108,4 +124,9 @@ static class HalAndHalFormsConfig {
108
124
static class AllConfig {
109
125
110
126
}
127
+
128
+ @ EnableHypermediaSupport (type = { })
129
+ static class NoConfig {
130
+
131
+ }
111
132
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2019 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .springframework .hateoas .support ;
17
+
18
+ import java .util .Collection ;
19
+
20
+ import org .springframework .hateoas .config .HypermediaMappingInformation ;
21
+ import org .springframework .hateoas .config .MediaTypeConfigurationProvider ;
22
+ import org .springframework .http .MediaType ;
23
+
24
+ /**
25
+ * @author Greg Turnquist
26
+ */
27
+ public class CustomHypermediaConfigurationProvider implements MediaTypeConfigurationProvider {
28
+
29
+ @ Override
30
+ public Class <? extends HypermediaMappingInformation > getConfiguration () {
31
+ return CustomHypermediaType .class ;
32
+ }
33
+
34
+ @ Override
35
+ public boolean supportsAny (Collection <MediaType > mediaTypes ) {
36
+ return mediaTypes .stream ().anyMatch (mediaType -> mediaType .isCompatibleWith (CustomHypermediaType .FRODO_MEDIATYPE ));
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ org.springframework.hateoas.config.MediaTypeConfigurationProvider=\
2
+ org.springframework.hateoas.support.CustomHypermediaConfigurationProvider
You can’t perform that action at this time.
0 commit comments