【发布时间】:2016-07-12 16:26:08
【问题描述】:
我正在尝试根据我的数据库 (MongoDB) 中的查询返回字符串列表。 我已经看过Jersey: Return a list of strings,但它对我没有用。
这里是查询代码:
public List<String> getAllContatos() {
// TODO Auto-generated method stub
List<String> contatos = new ArrayList<>();
MongoDatabase db = DaoFactory.getInstance().getMongoDatabase();
MongoCollection<Document> table = db.getCollection("Contatos");
for (Document doc : table.find())
contatos.add(doc.toJson());
return contatos;
}
这是 REST 代码:
@GET
@Path("/all")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllContacts() {
operations = new ContatoDaoImpl();
List<String> documents = operations.getAllContatos();
GenericEntity<List<String>> contacts = new GenericEntity<List<String>>(documents) {
};
return Response.ok(contacts).build();
}
但它仍在返回
GRAVE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<java.lang.String>.
提前谢谢大家。
【问题讨论】: