-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Fix multiple HTTP message converters of the same type being lost #48221
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
Fix multiple HTTP message converters of the same type being lost #48221
Conversation
When multiple HttpMessageConverters of the same specialized type (e.g., two JSON converters) were configured, only the last one was registered correctly. The first converter would be discarded because the specialized registration method was called for all converters of the same type, causing each to overwrite the previous one. This fix ensures that only the first converter of each specialized type (String, Kotlin Serialization JSON, JSON, XML) is registered using the specialized method (e.g., withJsonConverter()). Subsequent converters of the same type are registered as custom converters via addCustomConverter(). Signed-off-by: Tommy Karlsson <[email protected]>
4a774fd to
0be5a50
Compare
|
The behaviour you have described is intentional. Converters can be ordered to control which converter wins. What's your use case for having multiple JSON-compatibile converters registered at the same time and what logic do they have in place to ensure that they'll both be used? |
I have for example both |
|
Your proposed fix would result in I think there's room for improvement here, but I don't think this is the right approach. Please open an issue with as much detail as possible about the problem that you're facing (a small sample the reproduces it would be ideal) and we can take a further look. |
|
I don't think we do anything special with I think we're doing our best here with regards to the order of beans in the application context, but trying to sort out all possible combinations there and guessing the original intent won't work in my opinion. |
Yes that was my initial workaround when I found this issue. It works ofc. But I still believe the current behaviour in The spring boot documentation clearly states;
But that is not the case. The current behaviour is that e.g. all |
I'm not sure we should consider that as a workaround. We can probably improve the built-in customizers, but we should discuss that in a new issue with a minimal sample that demonstrates the problem.
We can probably improve the documentation there as the Spring Boot 3.x behavior was wrong in several ways. For example, the same list of converters was configured for both clients and server. The ordering and set of converters could be then wrong.
I think there is now a different mindset. I'm not sure the order of message converter beans in the application context should be necessarily 100% reflected in how
I'm not denying that. At startup time, we can only consider the media type supported by the converter for ordering. Those are at best heuristics, so we'll have to refine without making things too surprising for developers. I think that the customizer approach provides more control and is probably preferrable to complex heuristics. |
When multiple HttpMessageConverters of the same specialized type
(e.g., two JSON converters) were configured, only the last one was
registered correctly. The first converter would be discarded because
the specialized registration method was called for all converters
of the same type, causing each to overwrite the previous one.
This fix ensures that only the first converter of each specialized
type (String, Kotlin Serialization JSON, JSON, XML) is registered
using the specialized method (e.g., withJsonConverter()). Subsequent
converters of the same type are registered as custom converters via
addCustomConverter().