Basically there are two things which are important for me. The first one is already answered in the same way I would've done it (How to model a RESTful API with inheritance?). The RESTful design is easier to maintain when realized like:
GET /animals # get all animals
POST /animals # create a dog or cat
GET /animals/123 # get animal 123
Instead of:
GET /dogs # get all dogs
POST /dogs # create a dog
GET /dogs/123 # get dog 123
GET /cats # get all cats
POST /cats # create a cat
GET /cats/123 # get cat 123
I don't know how to setup a proper way of deserializing the following code into for example an object of type dog. I tend to get confused since most people advice on creating only an /animals POST endpoint instead of /animals/dog POST, but don't provide a direct solution to this.
The solutions I've found are:
TypeNameHandling.Auto (not secure unless custom serializer?)
Custom JsonConverter which also needs a custom implementation to tell which fields are in the derived classes as far as I'm concerned
JsonSubTypes(typeof(...)) annotation. This also needs including of fields from the derived classes in the custom mapping.
In the end I want to achieve the following. If this means this 'generic' solution in the end is not worth it, that's also an answer for me.
[HttpPost]
public async Task<ActionResult> Add(Animal animal)
{
// repo.add(animal);
}