spring-projects / spring-projects/spring-data-rest
Make UriToEntityConverter usable for just <id> not only ..../<resource>/<id>
@odrotbohm is already working on this.
Since Apr 11, 2022.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
I'm wondering what is this safe-check for in UriToEntityConverter.java How about removing it?
if (parts.length < 2) {
throw new ConversionFailedException(sourceType, targetType, source, new IllegalArgumentException(
"Cannot resolve URI " + uri + ". Is it local or remote? Only local URIs are resolvable."));
}
IMHO it's unnecessary. UriToEntityConverter just uses the last part of the URI and deduces type from targetType not uri path. So we could say that by design it assumes URI is relative to targetType's resource, however it forbids short URI imposing full resource path. In result:
http://localhost:8080/entity/1 is proper URI (although only "1" is actually taken from this)
/entity/1 is also a proper URI
1 is not resolvable URI anymore
Why? Such short relative URIs containing just ID are actually very useful and used by many frameworks.
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.