Can't set Content-type for Request Header when use Spring annotations
See original GitHub issueI’m using Feign and Spring annotations, I have a request that expects to accept “text/plain”.
@PostMapping(value = "/demo", consumes = "application/json", produces="text/plain")
public String demo(@RequestBody List<Long> ids);
But, the produces value not working. The request still has a header: Accept=application/json
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to Set JSON Content Type In Spring MVC - Baeldung
Let's start with a simple example of an API exposing a JSON string. Based on the content type present in the header, @ResponseBody...
Read more >Spring MVC 4: "application/json" Content Type is not being set ...
First thing to understand is that the RequestMapping#produces() element in @RequestMapping(value = "/json", method = RequestMethod.
Read more >17. Web MVC framework - Spring
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler ...
Read more >Using @Consumes and @Produces to Customize Requests ...
By default, a resource class can respond to and produce all MIME media types of representations specified in the HTTP request and response...
Read more >Spring RestController - DigitalOcean
Spring RestController annotation is used to create RESTful web services using Spring MVC. Spring RestController takes care of mapping request ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think that when use
@RequestBody, the server side should accept theContent-Type = "application/json"request. Here are some of my points:@RequestBody,it should usehandleConsumesAnnotation(data, "application/json");instead ofhandleProducesAnnotation(data, "application/json");@ResponseBody,it should usehandleProducesAnnotation(data, "application/json");instead ofhandleConsumesAnnotation(data, "application/json");I can’t say if was fixed or not, feel free to take a look