From 49146b46e36adfe30df87acf5bbaaef16bda0ff0 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 11:18:30 +0530 Subject: [PATCH] pagination: make the /echo transcript deterministic (LinkedHashMap instead of Map.of) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ic4b4bLvQVbZweAqqf54x --- pagination/output/13-pageable-binding.txt | 10 +++++----- .../java/com/ankurm/pagination/ProductController.java | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) 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; } /**