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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public class LegacyRepresentationConfigIntegrationTests extends AbstractReposito
|
||||
@Override
|
||||
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
||||
config.setDefaultMediaType(MediaType.APPLICATION_JSON);
|
||||
config.useHalAsDefaultJsonMediaType(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user