【发布时间】:2016-04-29 19:32:35
【问题描述】:
我编写了一个简单的类来测试响应读取实体方法(如果它按我预期的那样工作)。但效果并不好。
当我开始上课时,我在response.readEntity() 收到以下错误:
Exception in thread "main" java.lang.IllegalStateException: Method not supported on an outbound message. at org.glassfish.jersey.message.internal.OutboundJaxrsResponse.readEntity(OutboundJaxrsResponse.java:150)
这是我写的代码
public static void main(String[] args) {
List<Entity> representations = new ArrayList<>();
representations.add(new Entity("foo", "baz", false));
representations.add(new Entity("foo1", "baz1", true));
representations.add(new Entity("foo2", "baz2", false));
Response build = Response.ok(representations).build();
printEntitesFromResponse(build);
}
public static void printEntitesFromResponse(Response response) {
response
.readEntity(new GenericType<List<Entity>>() {})
.stream()
.forEach(entity -> System.out.println(entity));
}
我做错了什么?
【问题讨论】:
标签: java jersey jax-rs dropwizard