Description
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?