question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't set Content-type for Request Header when use Spring annotations

See original GitHub issue

I’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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
zwyStylecommented, Jun 22, 2021

I think that when use @RequestBody , the server side should accept the Content-Type = "application/json" request. Here are some of my points:

  • when parsing @RequestBody ,it should use handleConsumesAnnotation(data, "application/json"); instead of handleProducesAnnotation(data, "application/json");
  • when parsing @ResponseBody ,it should use handleProducesAnnotation(data, "application/json"); instead of handleConsumesAnnotation(data, "application/json");
0reactions
velocommented, Jul 1, 2022

I can’t say if was fixed or not, feel free to take a look

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found