spring-projects / spring-projects/spring-data-rest

Correctly serialize rel links to appropriate concrete implementation [DATAREST-358]

Open
#740 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: enhancement
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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.