I know, this has been asked before.
But I did check a bunch of those answers and could not find anything with the same context that solved the issue.
The code is very straight forward:
@GetMapping("")
@JsonView(Views.GetView.class)
public ResponseEntity<Page<User>> getUsers(
@ParameterObject Pageable pageable) {
System.out.println("pageable " + pageable);
//output pageable Page request [number: 0, size 20, sort: UNSORTED]
Page<User> allUsers = userRepository.findAll(pageable);
System.out.println("page user content " + allUsers.getContent());
//output page user content [User(id=2, name=Marshall, username=marshall44, [email protected], roles=[Role(name=ROLE_USER)])]
PageImpl<User> pagei = new PageImpl<>(allUsers.getContent());
System.out.println("page i " + pagei);
//output page i Page 1 of 1 containing com.serendipity.portfolio.entity.User instances
// return ResponseEntity.ok().body(pagei);
// this also returns {}
return ResponseEntity.ok().body(allUsers);
}
I included the output of each intermediate variable so as to have a better sense of what is developing.
The request coming from Swagger UI is http://localhost:8080/api/v1/users?page=0&size=20.
The issue was with
@JsonViewwhich did not match all properties ofUser.Adding this to
application.propertiessolved the issue: