Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17394

Content-Type not set correctly on @ControllerAdvice

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Works as Designed
    • Affects Version/s: 5.1.1
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Last commented by a User:
      true

      Description

      Given a class with @ControllerAdvice annotation

      @ControllerAdvice
      @RequestMapping(produces = {  "application/vnd.someapp-v1.0+json;charset=utf-8" })
      public class RestErrorHandler {
      ...
      @ExceptionHandler(OperationWithProblemsException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) 
      @ResponseBody public OperationResult processOperationWithProblemsException(OperationWithProblemsException ex) {  
        return ex.getResult();
      }

      When running with Spring 5.0.X the content type specified in the produces-attribute of the RequestMapping annotation was respected and sent to the client upon this exception.

      Starting with Spring 5.1.0 this has somehow changed and now I get 

      application/json;charset=UTF-8

      instead of the expected

      application/vnd.someapp-v1.0+json;charset=utf-8

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              mpapenbr mpapenbr
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 24 weeks, 1 day ago