-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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:
- AnnotationMethodHandlerAdapter.java (47.27 kB)
- ContentNegotatingResponseBody.java (5.91 kB)
- ContentNegotatingResponseBody.java (5.86 kB)
- MediaTypeUtil.java (4.29 kB)
Issue Links:
- @RequestMapping should support accept header and url extension [SPR-6497] #11163
@RequestMappingshould support accept header and url extension ("duplicates") - Content negotiation improvements [SPR-8410] #13057 Content negotiation improvements ("is superseded by")
9 votes, 7 watchers