Support for returning response bodies on deletion of item resources.
RepositoryRestConfiguration now allows to configure to return a response body for the deletion of item resources. The controller implementation follows the same patter we have already established for creation and updates: unless explicitly enabled or disabled we now consider the presence of an accept header as indicator of whether a response body should be rendered. This could be a "breaking" change for clients having explicitly expected 204 until now even for requests with an Accept header. If that's an issue, those should either explicitly disable the setting, do not submit an Accept header or loosen their expectations to expect either 200 or 2xx as indicator of success in general. Fixes #2225.
This commit is contained in:
@@ -61,6 +61,7 @@ public class RepositoryRestConfiguration {
|
||||
private boolean useHalAsDefaultJsonMediaType = true;
|
||||
private Boolean returnBodyOnCreate = null;
|
||||
private Boolean returnBodyOnUpdate = null;
|
||||
private Boolean returnBodyOnDelete = null;
|
||||
private List<Class<?>> exposeIdsFor = new ArrayList<Class<?>>();
|
||||
private ResourceMappingConfiguration domainMappings = new ResourceMappingConfiguration();
|
||||
private ResourceMappingConfiguration repoMappings = new ResourceMappingConfiguration();
|
||||
@@ -375,6 +376,30 @@ public class RepositoryRestConfiguration {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to return a response body after deleting an entity considering the given accept header.
|
||||
*
|
||||
* @param acceptHeader can be {@literal null} or empty.
|
||||
* @return
|
||||
* @since 4.1
|
||||
*/
|
||||
public boolean returnBodyOnDelete(String acceptHeader) {
|
||||
return returnBodyOnDelete == null ? StringUtils.hasText(acceptHeader) : returnBodyOnDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to return a response body after deleting an entity.
|
||||
*
|
||||
* @param returnBodyOnUpdate can be {@literal null}, expressing the decision shall be derived from the presence of an
|
||||
* {@code Accept} header in the request.
|
||||
* @return {@literal this}
|
||||
* @since 4.1
|
||||
*/
|
||||
public RepositoryRestConfiguration setReturnBodyOnDelete(Boolean returnBodyOnDelete) {
|
||||
this.returnBodyOnDelete = returnBodyOnDelete;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start configuration a {@link ResourceMapping} for a specific domain type.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user