Missing "consumes" on controller method results in Content-Type set to */*
See original GitHub issueIf for example a @PostMapping
annotation on a RestController does not have the “consumes” variable set to anything, the org.springdoc.core.MethodAttributes.fillMethods
method uses org.springframework.http.MediaType.ALL_VALUE
as the value, which is */*
.
This results in Spring throwing an exception saying java.lang.IllegalArgumentException: Content-Type cannot contain wildcard type '*'
in org.springframework.http.HttpHeaders.setContentType
Could it be possible that instead of using */*
, you would instead fill the array with a set of MediaTypes so that one could choose in the Swagger-ui, or default to org.springframework.http.MediaType.APPLICATION_JSON_VALUE
if the class is a RestController?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
Spring default consumes and produces - Stack Overflow
You have defined consumes and produces at the class level, which means by default all the REST services should pass headers, Content-Type ......
Read more >415 Unsupported Media Type - HTTP - MDN Web Docs
The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload ...
Read more >415 Unsupported MediaType in Spring Application - Baeldung
13: The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is...
Read more >Handling errors in ASP.NET Core Web API - DevTrends
This post looks at the best ways to handle exceptions, validation and other invalid requests such as 404s in ASP.NET Core Web API...
Read more >Using @RequestBody and @ResponseBody with Spring MVC
@RestController public class PersonController { @PostMapping(value = "/person", consumes = MediaType.APPLICATION_JSON_VALUE) public void savePerson(@RequestBody ...
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 FreeTop 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
Top GitHub Comments
Hi @AlfSimen,
The default value if consumes is missing will be set to org.springframework.http.MediaType.APPLICATION_JSON_VALUE, in the next release. If its not enough, we can use an array with a set of default MediaTypes.
I agree this defaulting to
*/*
is not ideal. In my case the AWS Gateway import tool doesn’t like that content type. At the very least we should be able to override this default value in some fashion.