2017-09-26 9 views
0

저는 JAX-RS에서 Spring에 이민 온 사람입니다. 내 다음 코드와 Spring에서 application/xml의 요소 목록에 어떻게 응답합니까?

,

@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); 
} 

나는 application/xml에 대한 application/json하지만 406에 대한 200를 얻을.

이 문제를 해결하는 가장 좋은 방법은 무엇입니까?

자동 복수 배치 기능이 있습니까?

은 여기 내 종속

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 
} 
+0

json 및 xml 메시지 변환기가 있습니까? Accept 헤더 (application/xml, application/json)가 다른 요청을 보내시겠습니까? –

+0

@DmitrySenkovich 네, 컬을 사용하여 테스트하고 있습니다. –

+0

나는'spring-boot-starter-web'도 사용하고 있습니다. 나는 기본적으로'HttpMessageConverter'를 설정하지 않는지 확인했습니다. 그래서 그것은 xml 구성을 잊어 버린 동안 json 변환기가있는 것처럼 보입니다. –

답변

0

내가 다른 사람을 위해 내 자신의 대답을 놓겠 어 온다.

다음 종속성을 추가했습니다.

// for application/xml 
// remove if you don't need to deal with XML. 
runtime 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.1'