/** * @see PageableResult#toSimpleObject(Converter) * @should add property totalCount if context contains parameter totalCount which is true * @should not add property totalCount if context contains parameter totalCount which is false * @should not add property totalCount if context does not contains parameter totalCount */ @Override public SimpleObject toSimpleObject(Converter preferredConverter) throws ResponseException { List<Object> results = new ArrayList<Object>(); for (T match : getPageOfResults()) { results.add(ConversionUtil.convertToRepresentation(match, context.getRepresentation(), preferredConverter)); } SimpleObject ret = new SimpleObject().add("results", results); boolean hasMore = hasMoreResults(); if (context.getStartIndex() > 0 || hasMore) { List<Hyperlink> links = new ArrayList<Hyperlink>(); if (hasMore) links.add(context.getNextLink()); if (context.getStartIndex() > 0) links.add(context.getPreviousLink()); ret.add("links", links); } if (Boolean.valueOf(context.getParameter("totalCount"))) { ret.add("totalCount", getTotalCount()); } return ret; }