-
Notifications
You must be signed in to change notification settings - Fork 38.5k
AllEncompassingFormHttpMessageConverter prioritizes Jackson 2 XML over JSON [SPR-13309] #17894
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 Can you elaborate what the actual end result error is? I think we are talking about #17831 which ensured that Jackson XML is preferred (over JAXB2) if it is available on the classpath. This was only intended to impact XML serialization however. Prior to that the AllEncompassingFormHttpMessageConverter used to register JAXB2 and Jackson JSON converters and that hasn't changed. I'm wondering if the issue you're running into is with using the RestTemplate and the order of registration of converters where the first converter to succeed is how the request body gets serialized and the Content-Type decided upon? If so we can probably update the order to preserve the order and which converters were registered at the front. This will avoid regressions where RestTemplate#postXxx and other such methods is involved since they can't specify a preferred Content-Type. At the same time it does make sense to register Jackson XML still since that helps where RestTemplate#exchange(Requestentity) and other such methods is involved and where the preferred Content-Type can be specified making it possible to pick JSON vs XML for example. |
Abhijit Sarkar commented The actual end result depends on the client, but in our case the request was rejected because the content type changed from JSON to XML. |
Rossen Stoyanchev commented
Right, this is what I thought. Although I'm not sure what you mean by "depends on the client" (who/what is the client?). Either way I presume that jackson-dataformat-xml is on the classpath. I assume that is intentional (it's only necessary if you care about XML serialization via Jackson)?
Wrong. Jackson JSON is still registered and preferred. As for why we register converters based on classpath, note that this is being done very carefully where the intent is very clear. In this case the effect is that (1) if jackson-dataformat-xml is on the classpath, it will be preferred over JAXB2, and (2) if Jackson is on the classpath it's preferred overy Gson. These are very reasonable assumptions that furthermore are very easy to override if you are in a situation where they don't work. The key issue I see here is the order of registration. I will provide a fix that you can try out. |
Abhijit Sarkar commented
You're right, I missed to see that the
I still contend that this should be left up to the user. Jackson XML has several limitations and I'm not entirely sure if Jackson JSON doesn't bring in some transitive dependencies on Jackson XML. In our case, we prefer JAXB over Jackson and the way private HttpMessageConverter xmlMessageConverter; // setter, getter
private HttpMessageConverter jsonMessageConverter; // setter, getter
|
Rossen Stoyanchev commented
Wrong. Jackson JSON and XML are separate dependencies. You need to remove The idea is to provide sensible out-of-the-box defaults. The suggested setters are unnecessary. If you don't like the defaults, just set the converters explicitly. What we need to do is fix the regression by ensuring that Jackson JSON comes before Jackson XML. Then all is good. |
Abhijit Sarkar opened SPR-13309 and commented
AllEncompassingFormHttpMessageConverter
forces Jackson XML without any option given to the user to choose an implementation. Until 4.1.7.RELEASE, Jackson JSON used to be the default and the code didn't set part converters exclusively (as it does now usingif-else
instead ofif
as was before). There's no log statements indicating what converters are chosen by default causing a whole lot of pain for people like me whose code is now broken.Affects: 4.2 GA
Attachments:
Issue Links:
Referenced from: commits 257cc63
The text was updated successfully, but these errors were encountered: