A Book has multiple authors, each of them may be either a Professional or an Amateur, e.g.:
class Book { String title; @OneToMany Set<Author> authors; }
class Person { String name; int age; }
class Author extends Person { @ManyToOne Book book; String licenseId; }
class AmateurAuthor extends Author { String favoriteColor; }
class ProfessionalAuthor extends Author { int professionalExperience; }
As you see, I have no info on the type of an author and I don't get any additional properties defined for their polymorphic projections. That means only the base projection (AuthorProjection), and not inherited projections (AmateurAuthorProjection, ProfessionalAuthorProjection) is considered when constructing the response.
Mikhail Kadan opened DATAREST-783 and commented
Consider the following case:
A Book has multiple authors, each of them may be either a Professional or an Amateur, e.g.:
Corresponding repositories:
And the following projections:
What do we have there is a Book having a set of Authors, each of them may be either an AmateurAuthor or a Professional Author.
What do I expect to get when I ask for a book resource/collection with a "default" projection:
But that's what I actually get:
As you see, I have no info on the type of an author and I don't get any additional properties defined for their polymorphic projections. That means only the base projection (AuthorProjection), and not inherited projections (AmateurAuthorProjection, ProfessionalAuthorProjection) is considered when constructing the response.
That could be future proved by defining:
And then requesting the "default2" provides:
Another approach I tried was:
But that way I get no projection for "authors" at all:
As for me this relates somehow to the https://jira.spring.io/browse/DATAREST-464 I have also included a sample project to demonstrate this issue
Affects: 2.4.2 (Gosling SR2)
Attachments:
1 votes, 1 watchers