0


I have an issue with one case when I want to make a pagination of my search results and one service is creating Page:
repository:

Page<Myth> findAllBy(Pageable pageable);

then the service class:

public Page<Myth> findAllBy(Pageable pageable) {
    return mythRepository.findAllBy(pageable);
}

then the controller:

@GetMapping("/allPageable")
@ResponseStatus(OK)
public Page<Myth> findAllMythsPageable(@RequestParam Integer size, @RequestParam Integer pageNumber){
    Pageable pageable = new PageRequest(pageNumber, size);
    return mythService.findAllBy(pageable);
}

The second service has such entry point on service class:

public List<Myth> findAllPageable(Integer size,  Integer pageNumber) {
    ResponseEntity<Myth[]> response = restTemplate.getForEntity(ROOT_URI
            + "/allPageable?size="
            + size
            + "&pageNumber="
            + pageNumber,Myth[].class);
    return Arrays.asList(response.getBody());
}


Unfortunately I cannot pass Page to a List and I get error that:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of(...)


Could you please help me how can I convert Page object into List so that it can be readible by Thymeleaf webpage (where I have foreach loop)? Or maybe you can advice me how to pass Page object into this:

ResponseEntity<Myth[]> response = restTemplate.getForEntity

Unfortunately when I do:

public Page<Myth> findAllPageable(Integer size,  Integer pageNumber) {
    ResponseEntity<Page[]> response = restTemplate.getForEntity(ROOT_URI
            + "/allPageable?size="
            + size
            + "&pageNumber="
            + pageNumber,Page[].class);
    return response.getBody()[0];
}

I get the same error...
Can I use Page object in Thymeleaf?
Thanks in advance for help!
Piotr

Piotr
  • 33
  • 1
  • 7
  • Possible duplicate of https://stackoverflow.com/questions/34099559/how-to-consume-pageentity-response-using-spring-resttemplate – Cata Oct 28 '18 at 03:57
  • Hi! Indeed i seems it was solved in this question mentioned in your comment @Cata ... Thanks! – Piotr Oct 28 '18 at 10:02
  • @Cata Actually I went a bit different way as I've created just a list of bulists for every page (by Guava Lists.partition) then I wrapped it in a specific class holding my list of necessary objects + info about current page number and total number of pages and then passed as a one entry list into ResponseEntity response = restTemplate.getForEntity – Piotr Oct 28 '18 at 14:14

0 Answers0