0

I'm currently building a rest controller with spring boot for user management.

I have a update user endpoint which receives a json file with the updated user data.

Now the problem is that there are different types of users which inherit from a base user... students and supervisors.

If I want to update a student, the json file has a "degree" values which a supervisor doesn't have.

So the following approach doesn't work because degree is not mapped to anything.

@PutMapping(value = "/users/current")
public void updateUser(@RequestBody User user)

Is there an approach to solve this without using two different routes for students and supervisors? It would need some kind of overloading...

fipps omat
  • 111
  • 3
  • just add the field to `User` (or create a class containing all fields) and let the degree field optional? – dan1st Jul 15 '22 at 17:05
  • It's not just degree so adding it to user would blow up user too much. Creating a class containing all values would work. But is that good style? That would be redundant code to the user/student/supervisor classes. – fipps omat Jul 15 '22 at 17:09
  • You could do something similar to https://stackoverflow.com/q/48733012/10871900 or https://www.baeldung.com/jackson-inheritance – dan1st Jul 15 '22 at 17:15

0 Answers0