I have 3 entities: Book
(parent), AntiqueBook
(extends Book), ScienceJournal
(extends Book).
The difference of AntiqueBook and ScienceJournal to Book is that each of them have an additional property than the parent (releaseYear
and scienceindex
, respectively).
Endpoint in the controller to create a new Book object:
@PostMapping("/books")
Book newBook(@RequestBody Book book) {
return service.save(book);
}
The method in service:
public Book save(Book book) {
return repository.save(book);
}
How can I create an AntiqueBook and ScienceJournal objects by only using this endpoint? For example, to check if @RequestBody has the property releaseYear (create AntiqueBook) or scienceIndex (create ScienceJournal). If it does not have either of these, then create Book.
For now, as a workaround, I created 2 additional endpoints to AntiqueBook and ScienceJournal, but I want to avoid this. I'm also having issues with the 'update' endpoint. If I can solve this one, then I can solve that one as well.