0
我的工作,我想从我的web服务返回的值列表一个小例子:REST风格的web服务返回的值列表
@GET
@Path("/string")
@Produces({"application/xml", "application/json"})
public List<String> test2()
{
List<String> list = new ArrayList<String>();
list.add("USA");
list.add("EGYPT");
return list;
}
我能够通过成功地调用这个服务来获得响应。
List list1 = client.target("http://localhost:8080/services/customers/string")
.request()
.accept(MediaType.APPLICATION_JSON)
.get(List.class);
它给我的数据为[USA, EGYPT]
但似乎我们需要使用GenericEntity按照这个帖子 - Jersey: Return a list of strings
或作为包装类 - How do return Java List<String> Json using Jax-RS
当我们需要使用这2个选项?是否需要使用GenericEntity或Wrapper类?
我正在使用JAX-RS2.0和Jersey实现。
据我所知它不是必需的,但是将其封装在'ResponseEntity'中例如允许您添加其他参数,例如html状态。 –
下面的链接可以帮助你弄清楚[Java类java.util.ArrayList ...和MIME媒体类型text/xml的消息正文编写器未找到](https://stackoverflow.com/a/41429076/8228918) –