How to automatically parse String @RequestBody as json

后端 未结 1 1552
情话喂你
情话喂你 2021-02-20 14:03

I have an endpoint which should read a string value as body.

@RestController
public class EndpointsController {
   @RequestMapping( method = RequestMethod.PUT, v         


        
相关标签:
1条回答
  • 2021-02-20 15:08

    If you're using Jackson as your JSON parser, you can simply declare your parameter with the type TextNode. This is the Jackson type representing JSON strings.

    public String updateName(@PathVariable(MY_ID) String myId, @RequestBody TextNode name) {
    

    You can then use its asText method to retrieve its text value.

    0 讨论(0)
提交回复
热议问题