diff --git a/pagination/output/13-pageable-binding.txt b/pagination/output/13-pageable-binding.txt index 71947ec..2cca0c7 100644 --- a/pagination/output/13-pageable-binding.txt +++ b/pagination/output/13-pageable-binding.txt @@ -1,5 +1,5 @@ -GET /products/echo -> 200 {"sort":"UNSORTED","size":20,"page":0} -GET /products/echo?page=2&size=5&sort=price,desc&sort=id -> 200 {"sort":"price: DESC,id: ASC","size":5,"page":2} -GET /products/echo?size=100000 -> 200 {"sort":"UNSORTED","size":2000,"page":0} -GET /products/echo?page=-3&size=0 -> 200 {"sort":"UNSORTED","size":20,"page":0} -GET /products/echo?page=abc -> 200 {"sort":"UNSORTED","size":20,"page":0} +GET /products/echo -> 200 {"page":0,"size":20,"sort":"UNSORTED"} +GET /products/echo?page=2&size=5&sort=price,desc&sort=id -> 200 {"page":2,"size":5,"sort":"price: DESC,id: ASC"} +GET /products/echo?size=100000 -> 200 {"page":0,"size":2000,"sort":"UNSORTED"} +GET /products/echo?page=-3&size=0 -> 200 {"page":0,"size":20,"sort":"UNSORTED"} +GET /products/echo?page=abc -> 200 {"page":0,"size":20,"sort":"UNSORTED"} diff --git a/pagination/src/main/java/com/ankurm/pagination/ProductController.java b/pagination/src/main/java/com/ankurm/pagination/ProductController.java index 8e8668e..b775c6b 100644 --- a/pagination/src/main/java/com/ankurm/pagination/ProductController.java +++ b/pagination/src/main/java/com/ankurm/pagination/ProductController.java @@ -62,7 +62,12 @@ public class ProductController { /** Shows what Spring MVC resolved from the query string, before any repository is involved. */ @GetMapping("/echo") public Map echo(Pageable pageable) { - return Map.of("page", pageable.getPageNumber(), "size", pageable.getPageSize(), "sort", pageable.getSort().toString()); + // LinkedHashMap, not Map.of: Map.of iterates in a different order on every JVM start, which would make the transcript differ run to run. + Map echoed = new java.util.LinkedHashMap<>(); + echoed.put("page", pageable.getPageNumber()); + echoed.put("size", pageable.getPageSize()); + echoed.put("sort", pageable.getSort().toString()); + return echoed; } /**