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:
@@ -38,6 +38,7 @@ public class RepositoryRestConfiguration {
|
||||
private String limitParamName = "size";
|
||||
private String sortParamName = "sort";
|
||||
private MediaType defaultMediaType = MediaTypes.HAL_JSON;
|
||||
private boolean useHalAsDefaultJsonMediaType = true;
|
||||
private boolean returnBodyOnCreate = false;
|
||||
private boolean returnBodyOnUpdate = false;
|
||||
private List<Class<?>> exposeIdsFor = new ArrayList<Class<?>>();
|
||||
@@ -202,7 +203,7 @@ public class RepositoryRestConfiguration {
|
||||
/**
|
||||
* Set the {@link MediaType} to use as a default when none is specified.
|
||||
*
|
||||
* @param defaultMediaType Default content type if none has been specified.
|
||||
* @param defaultMediaType default content type if none has been specified.
|
||||
* @return {@literal this}
|
||||
*/
|
||||
public RepositoryRestConfiguration setDefaultMediaType(MediaType defaultMediaType) {
|
||||
@@ -210,6 +211,30 @@ public class RepositoryRestConfiguration {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether HAL will be served as primary representation in case on {@code application/json} is requested. This
|
||||
* defaults to {@literal true}. If configured to {@literal false} the legacy Spring Data representation will be
|
||||
* rendered.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean useHalAsDefaultJsonMediaType() {
|
||||
return this.useHalAsDefaultJsonMediaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures whether HAL will be served as primary representation in case on {@code application/json} is requested.
|
||||
* This defaults to {@literal true}. If configured to {@literal false} the legacy Spring Data representation will be
|
||||
* rendered.
|
||||
*
|
||||
* @param useHalAsDefaultJsonMediaType
|
||||
* @return
|
||||
*/
|
||||
public RepositoryRestConfiguration useHalAsDefaultJsonMediaType(boolean useHalAsDefaultJsonMediaType) {
|
||||
this.useHalAsDefaultJsonMediaType = useHalAsDefaultJsonMediaType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to return a response body after creating an entity.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user