Description
Loi Huu Mai opened SPR-16205 and commented
I have a Rest API for download Media Resource. Inside this API, an exception would be thrown if some conditions are satisfied, no physical file found for example. I have a @ControllerAdvice
class which will catch that exception and returns a JSON Object.
The problem is when an exception is thrown and caught in ControllerAdvice, if I had the produces with MediaType.APPLICATION_JSON_VALUE stand first, it will work fine, a JSON Object will be returned.
@RequestMapping(value = "/download", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE})
{
"id": 2,
"message": "Test message"
}
However, MediaType.APPLICATION_OCTET_STREAM_VALUE stand first, 406 Not Acceptable status will be returned
@RequestMapping(value = "/download", method = RequestMethod.GET, produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE, MediaType.APPLICATION_JSON_VALUE}
I did some debug into the framework and found this:
!Debug.png|thumbnail!
The result should be the same regardless the order of produces.
Affects: 4.3.12
Reference URL: https://github.com/maihuuloi123/accept_mapping_bug.git
Attachments:
- Debug.png (98.65 kB)
Issue Links:
- Content negotiation fails with the conjonction of text/plain and ExceptionHandler [SPR-14411] #18982 Content negotiation fails with the conjonction of text/plain and ExceptionHandler ("duplicates")