Reputation: 79
From what I understand, this should not be possible in the first place. A generic is supposed to prevent this from happening. When I try to access the list, I get an InvocationTargetException (probably since it expects Post). This is the relevant section from my code:
List<Post> posts;
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "dateCreate"));
Pageable pageable = new PageRequest(pageIndex, pageSize, sort);
posts = postRepository.findAll(pageable);
This is the function in my repository:
List<Post> findAll(Pageable pageable);
The list that is actually returned contains one PageImpl
, and the PageImpl
contains the List<Post>
that was supposed to be returned in the first place.
Upvotes: 2
Views: 1595
Reputation: 614
Try :
Page<Post> findAll(Pageable pageable);
And convert it to list:
List<Post> postList = x.findAll(page).getContent();
Upvotes: 2