spring-projects / spring-projects/spring-hateoas
ExposesResourceFor annotation must support multiple classes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
I have a use case where I want to return different types of objects from my API method. These are not arbitrary classes but form an inheritance hierarchy. For instance, I have a summary view and a detail view returned from my API which uses a query parameter to determine the data to return. I have a Base bean that models the summary fields and a Detail bean that extends the summary fields to add other fields. My API signature returns the summary bean while my API implementation forms the returned beans as summary or detail bean depending on the query parameter.
In this case, I am unable to use Spring HATEOAS page assembler to create the links for summary or detail because there's no mapping for the controller type for the detail bean (since the controller is bound to only one resource).
I was able to work around this by creating custom classes for the time being but ended up needing to copy a lot of the code from the ControllerEntityLinks and the corresponding factory bean because they are not set up for extensibility (lot of the attributes are marked private and methods too).
I am happy to provide a fix for this by adding a new attribute to this annotation. It would be good not to have to copy the code from the default implementation.
Contributor guide
No contributing guide indexed for this repository
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 by reading the ExposesResourceFor annotation, ControllerEntityLinks, and the corresponding factory bean mentioned in the issue. Determine how the annotation could represent multiple classes and verify that the page assembler can create links for both summary and detail beans without copied implementation code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100