DATAREST-294 - RepositoryRestConfiguration has more fine grained control over media type defaults.

RepositorRestConfiguration now has a ….useHalAsDefaultJsonMediaType() which defaults to true. Configuring this to false allows to still use HAL as default media type in case no Accept header is set or it is set to */*. The flag decides what to return when an Accept header is set to application/json.
This commit is contained in:
Oliver Gierke
2014-04-29 10:09:15 +02:00
parent b69b715a66
commit 7dfdaa5114
3 changed files with 29 additions and 3 deletions

View File

@@ -372,7 +372,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
MediaType.valueOf("application/x-spring-data-compact+json")));
// Configure this mapper to be used if HAL is not the default media type
if (!config().getDefaultMediaType().equals(MediaTypes.HAL_JSON)) {
if (!config().useHalAsDefaultJsonMediaType()) {
mediaTypes.add(MediaType.APPLICATION_JSON);
}
@@ -394,7 +394,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
mediaTypes.add(MediaTypes.HAL_JSON);
// Enable returning HAL if application/json is asked if it's configured to be the default type
if (config().getDefaultMediaType().equals(MediaTypes.HAL_JSON)) {
if (config().useHalAsDefaultJsonMediaType()) {
mediaTypes.add(MediaType.APPLICATION_JSON);
}

View File

@@ -39,6 +39,7 @@ public class LegacyRepresentationConfigIntegrationTests extends AbstractReposito
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setDefaultMediaType(MediaType.APPLICATION_JSON);
config.useHalAsDefaultJsonMediaType(false);
}
}