Skip to content

XML request body cannot be deserialised by Spring web 5 with javax.xml.bind.annotation #25273

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

Closed
quancheng-zhao opened this issue Jun 17, 2020 · 4 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@quancheng-zhao
Copy link

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.

@wilkinsona
Copy link
Member

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.

@quancheng-zhao
Copy link
Author

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.

@wilkinsona
Copy link
Member

Thanks. The Spring MVC Showcase doesn't use Spring Boot. I'll ask the Spring Framework team to take a look.

@snicoll snicoll transferred this issue from spring-projects/spring-boot Jun 18, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 18, 2020
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 18, 2020
@poutsma
Copy link
Contributor

poutsma commented Feb 25, 2021

I believe this is by design, due to the support for Jackson XML (#16407) we introduced in 6665634.

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.

@poutsma poutsma closed this as completed Feb 25, 2021
@poutsma poutsma added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants