-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Make @RequestMapping inject the negotiated MediaType [SPR-9980] #14614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Rossen Stoyanchev commented The "negotiated MediaType" is not yet available at the time of controller method invocation. The actual content negotiation is in That said it seems like it would be nicer, in your example, if we provided an option to post-process the return value before it is written to the response. This would help What do you think? |
Michael Osipov commented Rossen, to the first paragraph: Yes, that would be nice to have a list of MediaType which are supported by the client. Would not solve my issue but may be handy for other purposes. Anyway why is MediaType not an Enum? to the second paragraph: This sounds good, one would move the if-else-clause to a single spot. But how would I know that, for instance the map from that exact method needs to be wrapped. Would this be per-controller just like a |
Rossen Stoyanchev commented
It's not quite an enum since you have wildcard types and subtypes, vendor extensions, XML or JSON compatible times (i.e. "*+json"), not to mention parameters like quality or charset and others.
This is something that would be registered globally. You would know the return type is ResponseEntity and you would be able to check the requested media type or the "producible" media type in order to decide. |
Michael Osipov commented
If you have to register this globally how is one supposed to know in this handler that for instance a simple (and very common) object like |
Rossen Stoyanchev commented In addition to the return type you would also have access to a |
Michael Osipov commented I am missing a link here. Is there something already where I could plugin such a thing than wrap my map in a custom object for that specific controller? |
Arnaud Cogoluègnes commented pull request for the list of requested media types as a method argument: #232 |
Rossen Stoyanchev commented Moving to general backlog now. See discussion under pull request for further details. |
Rossen Stoyanchev commented Resolving as "Won't fix". See pull request for further comments. |
Uh oh!
There was an error while loading. Please reload this page.
Michael Osipov opened SPR-9980 and commented
I have a use caes where I do return a suitable object according for the negotiated content type.
In my case I accept JSON and XML. When JSON is returned to the client I produce a Map, when XML is returned I produce a custom object.
There is no way to determine easily which content type will be written out to the client. With examining the Accept header and iterating over registered message converters.
I have a work around which looks like this:
and
I would rather have:
Affects: 3.1.3
Reference URL: http://stackoverflow.com/q/13272443/696632
Issue Links:
The text was updated successfully, but these errors were encountered: