Usually we pass key-value pair in JSON payload for POST/PUT request. Is it possible to pass a sting only ex:
If so what do we set the object for @RequestBody? Would it be String type or JSONObject?
CodePudding user response:
I did this:
@PostMapping(value = "businessdate", consumes = MediaType.TEXT_PLAIN_VALUE)
public void postBusinessDate(@RequestBody String businessDate) throws IOException, InterruptedException, SQLException {
businessDateService.updateBusinessDate(LocalDate.parse(businessDate));
}
and passed this:
CodePudding user response:
It would be a String. Even though you choose content type as application/json
CodePudding user response:
What worked for me is setting
@PutMapping(value = "/test/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
String updateInfo(@RequestHeader(@PathVariable("id") String id, @RequestBody String payload){...}
and passing the string payload by escacping the double quotes
updateInfo(token, id, "\"TEST\"");