1

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.

Community
  • 1
  • 1
luanlucas
  • 29
  • 6

1 Answers1

1

I was able to solve the problem changing my pom.xml dependencies and changing my method getAllContatos() and its return type.

Opal
  • 81,889
  • 28
  • 189
  • 210
luanlucas
  • 29
  • 6