spring-projects / spring-projects/spring-data-rest
Correctly serialize rel links to appropriate concrete implementation [DATAREST-358]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Benjamin Conlan opened DATAREST-358 and commented
When using an abstract entity type relation the Jackson serializer fails to build the correct concrete type (Can not construct instance of abstract entity) when enough information is provided to do so:
(I've attached an examplar source which is based upon the spring-boot data-rest sample)
In brief the entity hierarchy is as such:
- Accommodation (abstract)
- Hotel
- BedAndBreakfast
And the associating entity is a 'Reservation' which contains
{code:title:Reservation.java (partial)}
@NotNull
@ManyToOne
private Accommodation accommodation;
So when creating a reservation I would expect the Rest controller to resolve the concrete type of the Accommodation via the ref such as when performing
curl -X POST -H "Content-Type: application/json" http://localhost:8080/reservations -d '{"accommodation":"bedAndBreakfast/1", "price":99}'
And marshal an instance of 'BedAndBreakfast' but instead attempts to marshal the abstract type 'Accommodation'
Affects: 2.1 GA (Dijkstra)
Attachments:
- abstract-serialise-rest.zip (9.53 kB)
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.