Order of mediaTypesToUse list is different from the order of message converters #27724
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: declined
A suggestion or change that we don't feel we should currently apply
In AbstractMessageConverterMethodProcessor#writeWithMessageConverters method, it will create a list called
mediaTypesToUse
byacceptableTypes
andproducibleTypes
, its order is not added as we excepted, so it will cause choosing the wrongselectedMediaType
that will affect which converter to use.By the way, the
HTTP Header Accept Values
will be reordered byHeaderContentNegotiationStrategy
, this strategy may can solve this problem, even though this is not a same problem, and change this strategy is not such easy as #27488 mentioned.Steps:
Accept: text/html, */*
or:
Accept: text/html, application/json
CharSequence
typeWill treat as a string type:
Will produce a
mediaTypesToUse
:Both
MappingJackson2HttpMessageConverter
andStringHttpMessageConverter
can write the result value, but it will useStringHttpMessageConverter
, even thoughMappingJackson2HttpMessageConverter
is the first converter of converters now.Environment:
Windows 10 Pro, Spring version 5.3.8
The text was updated successfully, but these errors were encountered: