I'm developing an API Rest with Spring 4 and annotations swagger. Until now I was using'@RequestMapping(value = "/myapi/{id}", method = RequestMethod.GET, produces = "application/json; charset=UTF-8")'
, but I want to use the reduced version with GET:
@GetMapping("/myapi/{id}")
.
The problem is that swagger is not showing correctly the response content type:
Instead of it, I get the following:
response content type /
I have tried adding an HttpHeaders object to the response entity but not works.
Can you help me?
Annotation Type GetMapping. Annotation for mapping HTTP GET requests onto specific handler methods. Specifically, @GetMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod. GET) .
Spring MVC has made writing request handler controller classes and methods very easy. Just add a few annotations like @GetMapping and @PostMapping and put the class where component scanning can find them and configure them in the web application context.
Send JSON Data in POST Spring provides a straightforward way to send JSON data via POST requests. The built-in @RequestBody annotation can automatically deserialize the JSON data encapsulated in the request body into a particular model object. In general, we don't have to parse the request body ourselves.
Need to add the same optional params to the GetMapping
as your RequestMapping
.
@GetMapping(value = "/myapi/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With