Skip to content

Using @ResponseBody throws HttpMediaTypeNotAcceptableException when it supports writing an acceptable MediaType [SPR-6214] #10882

@spring-projects-issues

Description

@spring-projects-issues

Andrew Ebaugh opened SPR-6214 and commented

AnnotationMethodHandlerAdapter will throw a HttpMediaTypeNotAcceptableException in cases where the registered message converts should be able to support an acceptable representation.

It looks like the problem is in the following method: AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(...)
The inner-most part of the loop is only successful on this condition:
if (supportedMediaType.includes(acceptedMediaType)) {

If the acceptedMediaType is a wildcard, the condition fails. It seems it should rather be the revers:
if (acceptedMediaType.includes(supportedMediaType)) {

Then the fact that acceptedMediaType is a wildcard will make it potentially match what is supported.

The impact is that most client use a wildcard when Accept header is not explicitly set, and this results in a failure.

Will attach test.


Affects: 3.0 RC1

Attachments:

Issue Links:

Referenced from: commits 5310035

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions