spring-projects / spring-projects/spring-data-rest
Allow support for method-based annotation instead of field only.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
In my urge to show progress, I "hacked" JpaEntityMetada class so that it can find method based JPA annotations. (In my project, It would be a lot of domain classes to change to support field based JPA annotations, plus some refactor)
I added an if statement inside the for loop around the entityType.getAttributes() - line 42
for(Attribute attr : entityType.getAttributes()) {
boolean exported = true;
String memberName = attr.getJavaMember().getName(); // starts here:
if(StringUtils.startsWithIgnoreCase(memberName, "get"))
{
memberName = memberName.substring(3);
String firstChar = memberName.substring(0,1).toLowerCase();
memberName = firstChar.concat(memberName.substring(1));
}
Field field = ReflectionUtils.findField(type, memberName) //fix ends here
This works, however, I discovered that @oneToMany relationships do not map to resource links, instead collection resources are being "rendered" inside the owning resource.
BTW, if dependency injection was used instead of "newing" JpaEntityMetada I could have injected my own subclass avoiding the need to modify framework code. (Sorry I don't mean to be rude, just giving some feedback).
So, I'm guessing there is more work to do, besides the hack above. Right ?
In any case, I understand this area is being re-worked. I'm wondering if method based JPA annotations will be supported, or if I have to budget time to solve this on my own.
Thank you very much,
Paulo Avelar
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.
Research direction
Start with JpaEntityMetada, especially the loop over entityType.getAttributes() and the ReflectionUtils.findField call described around line 42. Trace how method-based JPA annotations are detected and how @OneToMany relationships become resource links; done means method-based annotations are supported without rendering collection resources inside the owning resource.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100