所以我有2个Pojos:
public class RequestDisplayInfo {
private int nombrePersonne;
private String courrielOrganisateur;
private RequestStatus statutDemande;
private String salleAssigne;
getters/setters.....
和
public class RequestsDisplayInfo {
private List<RequestDisplayInfo> acceptees = new ArrayList<RequestDisplayInfo>();
private List<RequestDisplayInfo> autres = new ArrayList<RequestDisplayInfo>();
getters/setters.....
当我返回第二堂课时,我得到这样的东西:
{
- acceptees: [1]
0: {
organizerEmail: "org"
participants: 45
requestStatus: "ACCEPTED"
roomName: "plt-2828"
}
- autres: [2]
-0: {
organizerEmail: "org"
participants: 2
requestStatus: "WAITING"
}
-1: {
organizerEmail: "org"
participants: 3
requestStatus: "WAITING"
}
}
以下是我返回的方式
@GET
@Path("/{email}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes({ "text/plain, text/html" })
public RequestByEmailDisplay displayByEmail(@PathParam("email") String email) {
List<Request> requests = requestService.displayByEmail(email);
RequestByEmailDisplay requestByEmailDisplay = new RequestByEmailDisplay();
requests.forEach(request -> {
if (request.isAccepted()) {
requestByEmailDisplay.getAcceptees().add(request.buildById());
}
});
requests.forEach(request -> {
if (!request.isAccepted()) {
requestByEmailDisplay.getAutres().add(request.buildById());
}
});
return requestByEmailDisplay;
}
这就是我想要的......除了它显示列表的大小以及每个元素的索引这一事实。
EDIT
我正在使用Jersey / Jackson并使用@Produces(MediaType.APPLICATION_JSON)
有谁知道为什么以及如何删除它?