spring-projects / spring-projects/spring-data-rest
The support for Resource Processor for Resources doesn't work correctly [DATAREST-274]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Faisal Feroz opened DATAREST-274 and commented
I have a resource named Product. I implemented a resource processor (code below) to attach links to resources:
@Component
public class ResourcesProcessor implements ResourceProcessor<Resources<Resource<Product>>> {
@Override
public Resources<Resource<Product>> process(
Resources<Resource<Product>> resources) {
// TODO: add links to resources here
return resources;
}
}
But the code never gets in to it. After debugging I found out that there is a bug in the ResourcesProcessorWrapper specifically in the following area:
private static boolean isValueTypeMatch(Resources<?> resources, TypeInformation<?> target) {
if (resources == null || !Resources.class.equals(resources.getClass())) {
return false;
}
Here it is explicitly checking for Resources.class which never happens as it always gets PagedResources in resources,getClass and check fails which in turn results in false for the whole check and resources processors never gets invoked.
Note: Things will work fine if I replace Product in the Resource Processor implementation with ? as doing so returns true of the following check and never gets into the actual type matching check due to short-circuit.
@Override
public boolean supports(TypeInformation<?> typeInformation, Object value) {
if (!RESOURCES_TYPE.isAssignableFrom(typeInformation)) {
return false;
}
return super.supports(typeInformation, value) || isValueTypeMatch((Resources<?>) value, getTargetType());
}
Affects: 2.0 GA (Codd), 2.0.1 (Codd SR1), 2.1 M1 (Dijkstra)
1 votes, 2 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.