0

**How can i pass Json Data in controller as a @RequestBody if i am passing as a Map. I want to manually pass the value. I have mentioned my source code down below. . . **

    @RestController
public class CustomerController {
    private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private CustomerService customerService;

    @PostMapping("/customer/save")
    public Result save(@RequestBody Map<String, Object> custData){

        logger.info(" :::::::::::::::::::: CoreCustomer Create Method ::::::::::::::::::::::");
        Result result = customerService.save(custData);
        return result;

    }
    @GetMapping("/customer")
    public Result getAll(){
        logger.info("::::::::::::::::::::: GetAll Method in Customer ::::::::::::::::::");
        Result result = customerService.getAll();
        return result;

    }

My Swagger UI is down below: enter image description here

In above image i am not able to get build-in input field. Could someone help me with this.

  • Possible duplicate of [Passing JSON Map into Spring MVC Controller](https://stackoverflow.com/questions/15684822/passing-json-map-into-spring-mvc-controller) – Suraj Gautam Nov 29 '19 at 06:57
  • Your code looks correct. If you annotate the parameter with `@RequestBody`, then the JSON is put in the `Map`. How exactly are you testing the REST call? Can you try with Postman or cURL ? – Wim Deblauwe Nov 29 '19 at 07:33

1 Answers1

0

Use Swagger don't need use @ApiImplicitParam annotation in Controller method ?

TiantianHe
  • 48
  • 1
  • 6