In my reactive REST API I'm trying to return an XML
response. However, I always get a JSON
, namely 406 NOT_ACCEPTABLE
. Any idea why?
@RestController
@RequestMapping(path = "/xml", produces = APPLICATION_XML_VALUE)
public class RestApi {
@GetMapping(path = "/get")
public Publisher<ResponseEntity> get() {
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(new Datta("test")));
}
@PostMapping(path = "/post", consumes = APPLICATION_XML_VALUE)
public Publisher<ResponseEntity<Datta>> post(@RequestBody Datta datus) {
datus.setTitle(datus.getTitle() + "!");
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(datus));
}
}
java.lang.AssertionError: Expected :application/xml Actual :application/json;charset=UTF-8
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id "io.spring.dependency-management" version "1.0.7.RELEASE"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.8"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
These are the links to my REST controller and a unit test. Thanks!