Skip to content

Content negotiation fails with the conjonction of text/plain and ExceptionHandler [SPR-14411] #18982

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions