Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content links missing when using Spring Data REST projections #513

Closed
tgeens opened this issue Mar 25, 2021 · 1 comment · Fixed by #514
Closed

Content links missing when using Spring Data REST projections #513

tgeens opened this issue Mar 25, 2021 · 1 comment · Fixed by #514
Labels

Comments

@tgeens
Copy link
Contributor

tgeens commented Mar 25, 2021

When using projections with the @Projection annotation in Spring Data REST, the content association in the HATEAOS _links section is missing.

That is because Spring Content looks for fields annotated with @ContentId to generate the link in ContentLinksResourceProcessor.

But projections have no fields, only methods. Putting the @ContentId annotation on a String getContentId() method in the projection interface does not help.

I think this could be resolved by not only considering the fields, but also looking at the propertyDescriptor.getReadMethod() when checking if the @ContentId annotation is present.

Pseudo code:

var propertyDescriptor = new BeanWrapperImpl(object).getPropertyDescriptors()[index];
if (AnnotationUtils.findAnnotation(propertyDescriptor.getReadMethod(), ContentId.class) != null) {
    ...
}

@paulcwarren would you consider such a change ?

@paulcwarren
Copy link
Owner

We are missing a test case in this area. Hence, this has snuck through.

But absolutely @tgeens. From what you describe that sounds like a reasonable fix to me.

paulcwarren added a commit that referenced this issue Mar 31, 2021
* Content links resource processor now detects and handles projections

Fixes #513
paulcwarren added a commit that referenced this issue Oct 27, 2021
* Content links resource processor now detects and handles projections

Fixes #513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants