spring-projects / spring-projects/spring-data-rest

Allow support for method-based annotation instead of field only. [DATAREST-152]

Open
#501 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Thomas Darimont opened DATAREST-152 and commented

Github Author: phavelar
Github Last-Updated: 2012-12-13T19:31:29Z
This issue was automatically imported from github

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


Reference URL: https://api.github.com/repos/SpringSource/spring-data-rest/issues/54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.