I'm doing a post request in SpringBoot and testing it with postman, but when I pass the body in Postman and try to read it in my application, it throws the error.
This is the method in Spring:
@PostMapping(path=PathConstants.START_ACTION)
public String start(@PathVariable String processDefinitionId, @RequestBody(required=false) String params){
if(params!=null) {
Gson gson = new Gson();
Map<String,Object> pvar = gson.fromJson(params, Map.class);
System.out.println(pvar);
}
}
In Postman I pass params this way:
I specified in the header the content-type as application/json
.
But then, if I pass my params using "Param" tab
it works. But I need to pass them as body and not params. Where is the problem here?
Header
Content-Type
isapplication-json
. So Spring try to construct yourjson
into aLinkedHashMap
.Now, try this...
instead of
and pass
header
thecontent-type
asapplication/json
. this will work..Now, if you still want to use your own old signature method like this ..
then in
header
thecontent-type
astext/plain
. then your older method will work also..