I have a Spring MVC backend Controller which I would like to have respond with different media types. In the case where the client indicates it accepts multiple media types, I would like the server to be able to prioritize which media type to respond with.
Specifically, I have methods annotated with:
@RequestMapping(method = RequestMethod.GET, value = "/mbean/attribute",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
and
@RequestMapping(method = RequestMethod.GET, value = "/mbean/attribute",
produces = MediaType.TEXT_PLAIN_VALUE)
From my testing, if the client indicates support for multiple media types, as in sending the header:
Accept: text/plain, application/octet-stream
Spring will respond with the first supported type in the list. (At least with my basic setup). Since I don’t control the client’s request, I would like the server to prioritize sending the response as application/octet-stream
regardless of the order of the types.
I’ve googled a bunch, but couldn’t find any examples of doing this and thus haven’t actually tried anything yet. However, I’d be surprised if Spring doesn’t have some way to achieve it.