Description
Mathieu POUSSE opened SPR-14411 and commented
When a client request an url with an "Accept" header such as "text/plain, application/json, */*" and the handler method that produces "text/plain" throws and exception that is handled with an @ExceptionHandler
that returns an object to serialize as json, the framework fails to negotiate the content and returns a 406.
This is because in org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor#writeWithMessageConverters(T, org.springframework.core.MethodParameter, org.springframework.http.server.ServletServerHttpRequest, org.springframework.http.server.ServletServerHttpResponse) at line 195, we take the first MediaType matching the requested and the productible (in this case text/plain).
Unfortunatly, there is no HttpMessageConverter able to serialize the object to text/plain and then it returns the 406.
Instead of that, it should proceed with the other MediaType matching the requested and productible types.
Affects: 4.2.6
Reference URL: https://github.com/mathieu-pousse/spring-framework-issues/tree/SPR-14411
Issue Links:
- @RequestMapping produces condition should not impact error responses [SPR-16318] #20865
@RequestMapping
produces condition should not impact error responses ("duplicates") - @RequestMapping get '406 Not Acceptable' when change 'produces' order [SPR-16205] #20753
@RequestMapping
get '406 Not Acceptable' when change 'produces' order ("is duplicated by") - @RequestMapping produces condition should not impact error responses [SPR-16318] #20865
@RequestMapping
produces condition should not impact error responses