FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
562 stars 221 forks source link

jackson-dataformat-xml changed the default response content type from 'application/json' to 'application/xml' #530

Closed VampireDaniel closed 1 year ago

VampireDaniel commented 2 years ago

Hello project maintainer

This is a really good module and helps us a lot in our java application, which some API need to response with XML

But during the integration with this module in our java spring boot application, some APIs response content type got unexpected changed from 'application/json' to 'application/xml' when no indication in HTTP content. before added this module everything would be returned in JSON, and everything works fine and well.

So after some research, seems some people have same issue as well, https://stackoverflow.com/questions/41036377/spring-mvc-changing-default-response-format-from-xml-to-json https://stackoverflow.com/questions/66752245/spring-5-jackson-dataformat-xml-forces-responsebody-with-xml https://stackoverflow.com/questions/57706610/how-to-set-default-messageconverter-to-json-with-jackson-dataformat-xml-added

The issue is easy to resolve, either to ask the client to indicate the Accept in header or add a limitation in Java service side, both work. But the reason still want to raise an issue here is to purpose, can the project maintainer add maybe one Warning Section/Headsup Section on the Readme page to let all of the developers know, there might have one potential check on API response after leveraging this module.

Thanks a lot.

cowtowncoder commented 2 years ago

Knowing this module, I cannot see this happening due to anything this module does. Format module does absolutely nothing to Spring: Spring uses this module, not the other way around. Module does not have any dependency to any Spring library and so does not even have means to directly change behavior. But the opposite is not true: Spring framework may well use auto-detection and change its behavior based on existence of Jackson modules. If so, Spring is in control of any changes. This seems to me to be the likeliest scenario.

So please ask on Spring users lists or support forums: jackson-dataformat-xml knows nothing about whether and how Spring framework changes its behavior based on Jackson format modules it finds.

I would be happy to add some verbiage on READMEs -- ideally links to something that explains the issue -- once the issue is understood. But at this point it is not clear to me what specifically happens. I can only speculate that Spring has auto-detection of Jackson modules and thereby does something that changes some behavior. But this really has everything to do with Spring; so this part needs to be understood.

Finally, please notice that there is another Jackson module -- jackson-jaxrs-xml-provider from https://github.com/FasterXML/jackson-jaxrs-providers/ -- that does register handlers to JAX-RS frameworks (which Spring might use via Jersey?). But it does not sound like you are adding that module.

VampireDaniel commented 2 years ago

@cowtowncoder Thanks a lot