I'm using a JOINED inheritance strategy for a class hierarchy which as follows:
abstract super class Product
concrete sub class Type1Product extends Product
concrete sub class Type2Product extends Product
Now i want to make a REST endpoint which allows users to POST data and for it to be parsed as a specific subclass of product, making sure its the same endpoint for any type of product. So something like the following:
@RequestMapping(method = POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public Product save(@Valid Product product) {
// ...
return product;
}
Currently when I try to post I get an error saying I can't initialize an abstract class, since Spring is trying to create a Product instance as opposed to an instance of the correct subtype.
Is what I'm trying to do possible? If not then what is the best practice or convention when making endpoints like this for an inheritance hierarchy?