Spring과 Jackson을 사용하여 RESTful WS를 사용하고 싶다.Spring MVC와 Jackson을 사용하여 RESTful WS 사용하기
@Controller
public class ConsumeWSController {
@RequestMapping(value = "/consumews", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Consume a RESTful webservice.", locale);
RestTemplate restTemplate = new RestTemplate();
Page page = restTemplate.getForObject("http://graph.facebook.com/juventus", Page.class);
model.addAttribute("pageAbout", page.getAbout());
model.addAttribute("pageAwards", page.getAwards());
return "consumews";
}
}
그리고 Page 클래스 :
@JsonIgnoreProperties(ignoreUnknown = true)
public class Page {
private String about;
private String awards;
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public String getAwards() {
return awards;
}
public void setAwards(String awards) {
this.awards = awards;
}
}
그러나 콘솔 반환이 오류 나는 페이스 북 그래프 (FC Juventus's JSON data-stream)
를 사용하여 가져 JSON 스트림을 고려하고 이 내 컨트롤러 :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [my.proj.Page] and content type [application/json;charset=UTF-8]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
이 오류를 어떻게 해결할 수 있습니까?
com.fasterxml.jackson.core.jackson-databind 2.3.0을 사용하고 있습니다. jackson-jaxrs-json-provider를 추가하면 Eclipse에서 Maven 오류가 반환됩니다. – vdenotaris