I have a spring boot application that accepts a JSON string in the body of the Http request. I made the controller like this
@RequestMapping(method = RequestMapping.POST, consumes = MediaType.APPLICATION_JSON_VALUE, value = "/foo")
public void acceptPost(@RequestBody TestModel t) {
....
}
My JSON string is like this
{
"name" : "ABC",
"age" : 20
}
Spring Boot is able to marshal the request body into the TestModel
POJO. But I am interested in doing the following
@RequestMapping(method = RequestMapping.POST, consumes = MediaType.APPLICATION_JSON_VALUE, value = "/foo")
public void acceptPost(String name, Integer age) {
....
}
The name
and age
comes in as arguments without there being an intermediate object to hold the JSON string as it was passed.
Is there any annotation that can be used or a way to override the existing interfaces or annotations in Spring Boot to help me get what I want?