1

I want to select the Json View applied to my data depending on an URL parameter. I am trying to implement this using @JsonView annotations, and I tried some solutions (1, 2). The thing is that those solutions are basen on the controller action returning a MappingJacksonValue, but I cannot use that because I am using pagination.

My action:

public ResponseEntity<Page<MyEntity>> findAll(
  int viewMode,
  Pageable pageable) {
    result = service.findAll(pageable);

  // Here I would like to apply a Json View to the result set depending 
  // on the variable viewMode

  return new ResponseEntity<Page<MyEntity>>(
    /* Resultset with the selected view applied, and paginated */, 
    HttpStatus.OK
  );
}
gmc
  • 3,910
  • 2
  • 31
  • 44

1 Answers1

1

To make @JsonView work with pagination, you need to set the following property to true in application.properties:

spring.jackson.mapper.DEFAULT_VIEW_INCLUSION = true

This will cause the mapper to also serialize properties which are not annotated, enabling paging to work.

Sync
  • 3,571
  • 23
  • 30