Home > Software design >  How to accept json data though post in spring boot rest
How to accept json data though post in spring boot rest

Time:08-20

PostMapping method

@RestController
@RequestMapping("/validate")
public class Validatesimapi {
    @PostMapping
    public Simoffers validateSim(@RequestBody ???)
}

I want to pass following json object through post request and accept it in validateSim. What should I write at ???. { "id": "1234", "num":"2343335" }

both the datatypes of id and num is String.

enter code here

CodePudding user response:

It’s as simple as adding a DTO with the fields that you want. The Jackson mapper will map the json to that object.

  • Related