Skip to content

Add content-negotiation to RequestBody and ResponseBody processing [SPR-6993] #11658

@spring-projects-issues

Description

@spring-projects-issues

Paul Austin opened SPR-6993 and commented

At the moment the AnnotationMethodHandlerAdaptor only uses a simple approach to content negotiation for RequestBody and ResponseBody parameters using the Accept and Content-type headers.

It would be useful if additional content negotiation, such as using file name extensions, request parameter and a default media type were also provided. This is similar to the approach provided by the ContentNegotiatingViewResolver for views.

I have implemented an example implementation if you'd like to use that as a basis for the implementation.

Look at the ServletHandlerMethodInvoker.handleResponseBodyMethod and the ServletHandlerMethodInvoker.resolveRequestBody. You'll see it uses a MediaTypeUtils class to get all the possible accepted media types.

The MediaTypeUtils uses the mediaTypeOrder field to decide which order the content negotiation should be performed in. This gives the developer the option to decide which types of content negotiation can be performed and the precedence order of these. The important thing to note is that all media types from all the selected sources are added so that there is fall back if one of the options is not supported by the different message converters.


Affects: 3.0.1

Attachments:

Issue Links:

9 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions