This commit adds support for XML serialization/deserialization based on the jackson-dataformat-xml extension. When using @EnableWebMvc or mvc:annotation-driven/, Jackson will be used by default instead of JAXB2 if jackson-dataformat-xml classes are found in the classpath.
This commit introduces MappingJackson2XmlHttpMessageConverter and MappingJackson2XmlView classes, and common functionalities between JSON and XML processing have been moved to AbstractJackson2HttpMessageConverter and AbstractJackson2View classes.
MappingJackson2XmlView supports serialization of a single object. If the model contains multiple entries, MappingJackson2XmlView.setModelKey() should be used to specify the entry to serialize.
Pretty print works in XML, but tests are not included since a Woodstox dependency is needed, and it is better to continue testing spring-web and spring-webmvc against JAXB2.
Issue: SPR-11785
Comment From: sdeleuze
@jhoeller In this PR, Jackson XML support is enabled as soon as the application includes jackson-dataformat-xml dependency. The reason why I did that is that JAXB2 will be in the classpath as soon as people use JDK6 or later, defeating automatic enabling of Jackson XML support for most users. On one side it could break existing applications, on the other side jackson-dataformat-xml is not a widely used library, I thought we could try to implement it that way, but it is perhaps too risky ...
Do you think I should keep or disable automatic usage of the Jackson XML support when jackson-dataformat-xml is on the classpath ?
Comment From: jhoeller
@sdeleuze, this looks fine for a start, let's get it in. I can do another review pass once it's in master.
There's just one thing we sort out right away: AbstractJackson2View is currently in the main web.servlet.view package; I'd rather have it in web.servlet.view.json, and just the XML variant in web.servlet.view.xml. We have general Jackson setup stuff in http.converter.json as well, so it should be alright to have our common view base class in web.servlet.view.json here, interpreting the "json" subpackage as a place for general Jackson stuff as well.
Comment From: sdeleuze
Thanks, I will modify AbstractJackson2View package (as well as AbstractJackson2HttpMessageConverter one) and push this commit to master.