-
-
Notifications
You must be signed in to change notification settings - Fork 524
ControllerAdvice content type defaults to */* #442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
With v1.2.32, you will be able to override the default produces mediaType: springdoc.default-produces-media-type=application/json |
@bnasslahsen Two questions regarding this fix: |
For 1), its already based on @RequestMapping annotation. But if you have better improvements, you can propose a PR. For 2), you have access to SpringDocConfigProperties Bean, so you can have full control: @Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor1(SpringDocConfigProperties springDocConfigProperties) {
return beanFactory -> springDocConfigProperties.setDefaultProducesMediaType(MediaType.APPLICATION_JSON_VALUE);
} |
Cannot solve the exception for with preset Content-Type 'video/mp4' .While playing video |
If you are reporting a bug, please help to speed up problem diagnosis by providing as
Please make sure you have read the section Using GitHub Issues in the contribution guide. |
When building a class annotated with '@ControllerAdvice' to handle exception conversion to JSON the default content type is '/' which is not ideal. At the very least we should be able to override this at the class level with an annotation that overrides the behavior.
Steps to reproduce the behavior:
What version of spring-boot you are using?
2.2.2.RELEASE
What modules and versions of springdoc-openapi are you using?
name: 'springdoc-openapi-ui', version: '1.2.31'
name: 'springdoc-openapi-security', version: '1.2.31'
What is the actual and the expected result using OpenAPI Description (yml or json)?
Actual something like: "content":{"/"..."
Expected something like: "content":{"application/json"..."
I have actually found a work to annotate your methods with:
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(value = Exception.class) @RequestMapping(method = { GET, POST, PUT, DELETE, PATCH }, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<ExceptionReportViewModel> handleException(HttpServletRequest req, Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); }
I don't like having to apply all the methods to the RequestMapping annotation as that's not recommended. I would like to be able to apply a RequestMapping at the class level and have that be used like such:
@ControllerAdvice @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE) public class UseJsonExceptionResponseControllerAdvice {
This doesn't work unfortunately. Is there another way this should be done or is this an enhancement to be made?
The text was updated successfully, but these errors were encountered: