I am using Spring Boot and I have a method defined like this in my controller
@PostMapping("/update)
public void update(@RequestBody User user) {
...
}
However in my post request from client(frontend or postman for example), I have something like this:
{
"firstName" : "John",
"lastName" : "Doe",
"id" : 1234,
"metaInfoId" : "5457sdg26sg4636"
}
The thing is my User pojo has only firstName, id and lastName instance fields in it.However in my request I have to send metaInfoId as well for some other needs. So how can I retrieve or separate metaInfoIdand User model in my controller method above?
Do I have to create another model class called UserModelRequest and add all User fields along with metaInfoId field and then use @RequestBody? Is there a way to simply remove metaInfoId from the request and then take everything else and dump it into User pojo? You could do this easily in nodejs for example(just splice your object and take what you need).
So is there a way to do it in java spring without having to create another model class?