I'm trying to return a list of Strings based on a query in my database (MongoDB). I've already taken a look on Jersey: Return a list of strings, but it hasn't worked for me.
Here is the query code:
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;
}
And here is the REST code:
@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();
}
But it is still returning
GRAVE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<java.lang.String>.
Thank you all in advance.