2016-07-11 2 views
1

데이터베이스 (MongoDB)의 쿼리를 기반으로 문자열 목록을 반환하려고합니다. 나는 이미 Jersey: Return a list of strings을 살펴 봤지만 나에게 도움이되지 못했다. 여기 Java - 문자열 목록을 반환하는 Jersey

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>. 

사전에 여러분 모두 감사합니다 반환합니다.

답변

1

내 pom.xml 종속성을 변경하고 내 메서드 getAllContatos() 및 그 반환 유형을 변경하는 문제를 해결할 수있었습니다.

관련 문제