我收到的错误:
SEVERE: A message body reader for Java class java.util.List,
and Java type java.util.List<com.testapp.Category>,
and MIME media type text/html; charset=utf-8 was not found
Run Code Online (Sandbox Code Playgroud)
尝试使用带有Jersey的GET方法从Rest服务使用JSON响应.当我使用curl时,服务器的响应如下所示:
[{"category":{"id":"4d9c5dfc8ddfd90828000002","description":"Cows"}},
{"category":{"id":"4d9c5dfc8ddfd90828000023","description":"Dogs"}},
...
{"category":{"id":"4d9c5dfc8ddfd90828000024","description":"Mules"}}]
Run Code Online (Sandbox Code Playgroud)
使用服务:
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>>(){});
}
Run Code Online (Sandbox Code Playgroud)
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 = …Run Code Online (Sandbox Code Playgroud)