Hello, when upgrading SpringBoot from 1.x to 2.x, Restful apis which consumes xml as request body are broken because values are deserialised to null.
API is like:
@RequestMapping(
method = POST,
consumes = {APPLICATION_XML_VALUE, TEXT_XML_VALUE},
produces = {APPLICATION_XML_VALUE, TEXT_XML_VALUE})
Response postSomething(@ApiParam(name = "Request", value="A valid <Request /> xml query") @Valid @RequestBody **XmlRequest** xmlRequest);
XmlRequest used javax.xml.bind.annotation. Then I changed annotation to jackson-dataformat-xml, request body can be deserialised as before.
I don't find any report about javax xml problem. Does SpringBoot 2 have some limitation to use this package? Should XML deserialisation use jackson xml databinding? When I refactored the code, I find out jackson xml databing has less annotation and it works not well with polymorphic subtypes.
Thanks for your help.
Comment From: wilkinsona
What version of Java are you running your application on? Java 9 made some changes around JAX-B so that some classes are no longer available by default. There's some information about this in the Spring Boot wiki.
If you don't think the above applies here then I'm not sure what the problem may be. It's hard to tell from what you've shared thus far. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: quancheng-zhao
Hello, Thanks for your quick reply.
I forked a simple Spring mvc demo and created a simple controller to reproduce the problem . Here is my test case branche https://github.com/quancheng-zhao/spring-mvc-showcase/pull/1/files.
ResourceController.java has two xml consumed api. /test/javax uses javax dto. /test/fasterxml uses jackson xml dto. Controller will print whether values are null or not.
Here is the printed result on my local, values deserialised by javax are null. `>>>>>>> jackson xml header is not null jackson xml header's id is not null jackson xml header's name is not null
======= javax header is not null javax header's id is null javax header's name is null `
I hope this sample will help. Thank you.
Comment From: wilkinsona
Thanks. The Spring MVC Showcase doesn't use Spring Boot. I'll ask the Spring Framework team to take a look.
Comment From: poutsma
I believe this is by design, due to the support for Jackson XML (#16407) we introduced in 6665634675da1230339e9e5749f0693fd09a68ff.
Effectively, this means that the Jackson XML mapper takes precedence over the JAXB converter. You can customize the order of the converters by overriding extendMessageConverters in your WebMvcConfig.