0
Ich bin ein Einwanderer von JAX-RS zu Spring.Wie kann ich eine Liste von Elementen in der Anwendung/xml mit Spring antworten?
Mit meinem folgenden Code,
@RequestMapping(method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE})
public @ResponseBody ResponseEntity<List<Item>> read() {
final List<Item> body
= range(0, current().nextInt(1, 10))
.mapToObj(i -> Item.newRandomInstance())
.collect(toList());
return ResponseEntity.ok(body);
}
ich 200
für application/json
aber 406
für application/xml
.
Was ist der beste Weg, um dieses Problem zu lösen?
Gibt es Funktionen für die automatische Mehrfachverpackung?
kommt meine Abhängigkeiten
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
// exclude module: "spring-boot-starter-tomcat"
}
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
// compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile("org.springframework.boot:spring-boot-configuration-processor")
testCompile('com.jayway.jsonpath:json-path') // for gs-rest-service
// ----------------------------------------------------------------------------------------------- springfox-swagger
compile 'io.springfox:springfox-swagger2:2.7.0'
compile 'io.springfox:springfox-swagger-ui:2.7.0'
//compile('org.springframework.boot:spring-boot-starter-amqp') // rabbitmq
}
Haben Sie beide JSON und XML-Nachrichtenkonverter? Senden Sie Anfragen mit unterschiedlichen Accept-Header (application/xml, application/json)? –
@DmitrySenkovich Ja, ich teste mit Curl. –
Ich benutze auch 'Spring-Boot-Starter-Web'. Ich habe überprüft, dass es standardmäßig keine 'HttpMessageConverter 'konfiguriert. So scheint es, als ob Sie JSON-Konverter haben, während vergessen wurde, für XML zu konfigurieren –