spring-projects / spring-projects/spring-data-rest
Projections do not support generics
Open
@odrotbohm is already working on this.
Since Sep 13, 2023.
status: feedback-provided
status: waiting-for-triage
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
I don't know if it by design, but projections do not (properly?) support generics. For example, if I have:
public interface GenericCollectionSummary<E> {
List<E> getMembers();
}
interface SpecialisedProjection extends GenericProjection<ValueProjection> {
}
Then the resulting JSON will not represent values as ValueProjection, but as the JSON format for its backing type.
So if we have:
class Person {
String name;
String surname;
String getName(){}
String getSurname(){}
}
class Club {
List<Person> members;
List<Person> getMembers(){}
}
and
@Projection(name = "summary", types = Person.class)
interface PersonSummary {
@Value("#{target.name + ' ' + target.surname}")
String getFullName();
}
@Projection(name = "summary", types = Club.class)
public interface ClubSummary extends GenericCollectionSummary<PersonSummary> {
}
So given a list of clubs using such projection such as { members: [{name: 'John', surname: 'Doe'}] }, you'll get the following projection:
{
"values": [
{
"name": "John",
"surname": "Doe"
}
]
}
rathern than the expected:
{
"values": [
{
"fullName": "John Doe"
}
]
}
See attached demo for a runtime demonstration.
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.