pagination: make the /echo transcript deterministic (LinkedHashMap instead of Map.of)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4bLvQVbZweAqqf54x
This commit is contained in:
Claude
2026-11-16 11:18:30 +05:30
parent 91938727f2
commit 49146b46e3
2 changed files with 11 additions and 6 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
GET /products/echo -> 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 {"sort":"price: DESC,id: ASC","size":5,"page":2} 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 {"sort":"UNSORTED","size":2000,"page":0} GET /products/echo?size=100000 -> 200 {"page":0,"size":2000,"sort":"UNSORTED"}
GET /products/echo?page=-3&size=0 -> 200 {"sort":"UNSORTED","size":20,"page":0} GET /products/echo?page=-3&size=0 -> 200 {"page":0,"size":20,"sort":"UNSORTED"}
GET /products/echo?page=abc -> 200 {"sort":"UNSORTED","size":20,"page":0} GET /products/echo?page=abc -> 200 {"page":0,"size":20,"sort":"UNSORTED"}
@@ -62,7 +62,12 @@ public class ProductController {
/** Shows what Spring MVC resolved from the query string, before any repository is involved. */ /** Shows what Spring MVC resolved from the query string, before any repository is involved. */
@GetMapping("/echo") @GetMapping("/echo")
public Map<String, Object> echo(Pageable pageable) { public Map<String, Object> 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<String, Object> echoed = new java.util.LinkedHashMap<>();
echoed.put("page", pageable.getPageNumber());
echoed.put("size", pageable.getPageSize());
echoed.put("sort", pageable.getSort().toString());
return echoed;
} }
/** /**