오류를 GET 나머지 서비스에서 JSON 목록을 소모한다.자바는 내가받을
[{"category":{"id":"4d9c5dfc8ddfd90828000002","description":"Cows"}},
{"category":{"id":"4d9c5dfc8ddfd90828000023","description":"Dogs"}},
...
{"category":{"id":"4d9c5dfc8ddfd90828000024","description":"Mules"}}]
과 서비스를 소비 :
public List<Category> getAnimalCategories(Cookie cookie) {
Client client = Client.create(new DefaultClientConfig());
ClientResponse response = client
.resource(Constants.BASE_URL)
.path(Constants.CATEGORIES_ANIMALS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.cookie(cookie)
.get(ClientResponse.class);
return response.getEntity(new GenericType<List<Category>>(){});
}
Category.java은 여기서
public class Category {
public String id;
public String description;
public Category() {
}
public Category(String id, String description) {
super();
this.id = id;
this.description = description;
}
이 서비스는 쿠키를 기반으로 사용 나는 곱슬 곱슬 사용할 때 서버의 응답은 다음과 같다 인증 - 그 부분이 작동하고 쿠키로 작업하는 다른 서비스 호출이 있습니다. 또한 새로운 응답 클래스를 사용하는 데 필요한
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getClasses().add(JacksonJsonProvider.class);
Client client = Client.create(clientConfig);
return client
.resource(Constants.BASE_URL)
.path(Constants.CATEGORIES_ANIMALS)
.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.cookie(cookie)
.get(new GenericType<List<AnimalCategoryResponse>>(){});
: - 문제를 해결하기 위해 잭슨 1.9.6 lib 디렉토리를 사용
가능한 중복 저지 클라이언트를 사용하는 JSON 객체 배열] (http://stackoverflow.com/questions/9627170/cannot-unmarshal-a-json-array-of-objects-using-jersey-client) –
Jackson 1.9를 추가하여 수정. 6 jar를 추가하고 ClientConfig에 추가합니다. clientConfig.getClasses(). add (Jackso nJsonProvider.class); –