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.

Missing "consumes" on controller method results in Content-Type set to */*

See original GitHub issue

If 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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

1reaction
springdoccommented, Dec 22, 2019

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.

1reaction
bfs-natewallmancommented, Dec 18, 2019

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.

Read more comments on GitHub >

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

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