Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@GetMapping not produces response content type application/json

Tags:

spring

swagger

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?

like image 601
silvia Dominguez Avatar asked Sep 13 '17 12:09

silvia Dominguez


People also ask

What is the use of @GetMapping annotation?

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) .

Can we use @GetMapping in Spring MVC?

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.

How pass JSON object in post request in spring boot?

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.


1 Answers

Need to add the same optional params to the GetMapping as your RequestMapping.

@GetMapping(value = "/myapi/{id}", produces = MediaType.APPLICATION_JSON_VALUE)

like image 61
Darren Forsythe Avatar answered Nov 15 '22 08:11

Darren Forsythe