spring-data-rest
spring-data-rest copied to clipboard
Projections do not support generics
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.
If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal sample that reproduces the problem. Please let us know in which context you're using projections (repositories, custom controller methods, …) so we can understand the use case.
Sorry about that, I had to draft quickly bicause of time constraints and I didn't want to forget it. I've improved the description.
Also, here is an example demonstrating the issue demo.zip
Any update on this one?