Hi,

Jackson-xml marshalling seems to be broken in the 2.0.0 M2 milestone release for Spring boot (with web-flux). I tried both with functional web routers and a 'classic' (simple) annotation based controller (kotlin):

data class Hello(val one: String, val two: String)

@Bean
fun apiRouter() = router {
    GET("/hello") { req ->
        ok().contentType(MediaType.APPLICATION_XML)
                .body(BodyInserters.fromObject(Hello("Hello", "World")))
    }
}

And

data class Hello(val one: String, val two: String)

@RestController
class HelloController {
    @GetMapping("/hello") fun sayHello() = Hello("Hello", "World")
}

The jackson XML marshaller doesn't seem to be registered automatically anymore.

Steps to reproduce

  • Create a Spring Boot project (start.spring.io) -> 2.0.0 M2 with the reactive web dependency;
  • Add a restcontroller that returns a simple entity (see above);
  • Add jackson-dataformat-xml dependency.

Call the endpoint with the application/xml accept header. The sever will respond with a 406 - not acceptable response. In the logging this shows up:

2017-06-23 12:39:42.629 ERROR 26064 --- [ctor-http-nio-2] o.s.w.s.h.ResponseStatusExceptionHandler : Response status 406 with reason "Could not find acceptable representation"

Verification

I've tried a similar approach with Spring Boot 1.5.4 and there it works as expected, depending on the provided accept header (application/xml or application/json) the application responds with the response in the requested format.

Comment From: jwalgemoed

Additional note, when using the routerfunction (webflux) the error is slightly different:

org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/xml' not supported
    at org.springframework.web.reactive.function.BodyInserters.lambda$null$16(BodyInserters.java:318) ~[spring-webflux-5.0.0.RC2.jar:5.0.0.RC2]
    at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_66]
    at org.springframework.web.reactive.function.BodyInserters.lambda$bodyInserterFor$17(BodyInserters.java:314) ~[spring-webflux-5.0.0.RC2.jar:5.0.0.RC2]
    at org.springframework.web.reactive.function.server.DefaultServerResponseBuilder$BodyInserterServerResponse.writeTo(DefaultServerResponseBuilder.java:312) ~[spring-webflux-5.0.0.RC2.jar:5.0.0.RC2]
    at org.springframework.web.reactive.function.server.support.ServerResponseResultHandler.handleResult(ServerResponseResultHandler.java:98) ~[spring-webflux-5.0.0.RC2.jar:5.0.0.RC2]

Comment From: bclozel

I guess you can't really compare with MVC and Boot 1.5 in that case; jackson-dataformat-xml is supported in Spring MVC, but it's not (yet) the case in Spring WebFlux. We can't support that in Boot until the proper codecs are implemented in Spring Framework.

Could you create a Spring Framework issue and report back here once it's done?

Thanks!

Comment From: jwalgemoed

Apologies, I just assumed the issue would be limited to Spring Boot - but it actually makes a lot of sense that it doesn't. I'll create the issue for Spring Framework and will keep you posted on the results here.

Comment From: jwalgemoed

Issue for Spring Framework created here: https://jira.spring.io/browse/SPR-15697

Comment From: Clockwork-Muse

Excuse me, is there any update for this?

Comment From: bclozel

@Clockwork-Muse It's blocked - waiting on FasterXML/jackson-dataformat-xml#260

Comment From: Sergey80

what is work-around?

Comment From: sdeleuze

See https://github.com/spring-projects/spring-framework/issues/20256#issuecomment-461445951.