Skip to content

Commit 64ece65

Browse files
committed
Tweak HAL-FORMS setup to fall back on HAL as media type if no templates registered.
Fixes GH-2418.
1 parent cda0825 commit 64ece65

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@
6767
import org.springframework.data.rest.core.support.RepositoryRelProvider;
6868
import org.springframework.data.rest.core.support.SelfLinkProvider;
6969
import org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory;
70-
import org.springframework.data.rest.webmvc.*;
70+
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
71+
import org.springframework.data.rest.webmvc.BaseUri;
72+
import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler;
73+
import org.springframework.data.rest.webmvc.HttpHeadersPreparer;
74+
import org.springframework.data.rest.webmvc.ProfileResourceProcessor;
75+
import org.springframework.data.rest.webmvc.RepositoryRestExceptionHandler;
76+
import org.springframework.data.rest.webmvc.RepositoryRestHandlerAdapter;
77+
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
78+
import org.springframework.data.rest.webmvc.RestMediaTypes;
7179
import org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter;
7280
import org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter;
7381
import org.springframework.data.rest.webmvc.convert.UriListHttpMessageConverter;
@@ -110,6 +118,7 @@
110118
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
111119
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalHandlerInstantiator;
112120
import org.springframework.hateoas.mediatype.hal.forms.HalFormsConfiguration;
121+
import org.springframework.hateoas.mediatype.hal.forms.HalFormsHttpMessageConverter;
113122
import org.springframework.hateoas.mediatype.hal.forms.Jackson2HalFormsModule;
114123
import org.springframework.hateoas.server.LinkRelationProvider;
115124
import org.springframework.hateoas.server.core.EvoInflectorLinkRelationProvider;
@@ -606,12 +615,7 @@ TypeConstrainedMappingJackson2HttpMessageConverter halFormsJacksonHttpMessageCon
606615
defaultedRelProvider, curieProvider, resolver.getObject(), configuration.getHalConfiguration(),
607616
applicationContext.getAutowireCapableBeanFactory()));
608617

609-
TypeConstrainedMappingJackson2HttpMessageConverter converter = new TypeConstrainedMappingJackson2HttpMessageConverter(
610-
RepresentationModel.class);
611-
converter.setSupportedMediaTypes(Collections.singletonList(MediaTypes.HAL_FORMS_JSON));
612-
converter.setObjectMapper(mapper);
613-
614-
return converter;
618+
return new HalFormsHttpMessageConverter(applicationContext, mapper);
615619
}
616620

617621
public ObjectMapper halObjectMapper(LinkCollector linkCollector) {
@@ -682,9 +686,9 @@ public RequestMappingHandlerAdapter repositoryExporterHandlerAdapter(
682686

683687
/**
684688
* The {@link HandlerMapping} to delegate requests to Spring Data REST controllers. Sets up a
685-
* {@link DelegatingHandlerMapping} to make sure manually implemented {@link BasePathAwareController} instances that
686-
* register custom handlers for certain media types don't cause the {@link RepositoryRestHandlerMapping} to be
687-
* omitted. See DATAREST-490.
689+
* {@link DelegatingHandlerMapping} to make sure manually implemented
690+
* {@link org.springframework.data.rest.webmvc.BasePathAwareController} instances that register custom handlers for
691+
* certain media types don't cause the {@link RepositoryRestHandlerMapping} to be omitted. See DATAREST-490.
688692
*
689693
* @return
690694
*/

0 commit comments

Comments
 (0)