From fb97c3784a412204bf3be8a0ce467b32fc816635 Mon Sep 17 00:00:00 2001 From: Libo Song Date: Wed, 7 Feb 2024 11:06:28 -0500 Subject: [PATCH 1/2] Make output of map sorted by key in pprint. --- .../com/hubspot/jinjava/lib/filter/PrettyPrintFilter.java | 7 +++++-- .../hubspot/jinjava/lib/filter/PrettyPrintFilterTest.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilter.java b/src/main/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilter.java index a0777f701..8132aaeae 100644 --- a/src/main/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilter.java +++ b/src/main/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilter.java @@ -10,6 +10,7 @@ import com.hubspot.jinjava.objects.date.PyishDate; import java.util.Map; import java.util.Objects; +import java.util.TreeMap; @JinjavaDoc( value = "Pretty print a variable. Useful for debugging.", @@ -45,10 +46,12 @@ public Object filter(Object var, JinjavaInterpreter interpreter, String... args) var instanceof String || var instanceof Number || var instanceof PyishDate || - var instanceof Iterable || - var instanceof Map + var instanceof Iterable ) { varStr = Objects.toString(var); + } else if (var instanceof Map) { + TreeMap map = new TreeMap((Map) var); + varStr = Objects.toString(map); } else { try { varStr = diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilterTest.java index 22cf1b650..2f1c1195b 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/PrettyPrintFilterTest.java @@ -52,8 +52,8 @@ public void ppPyDate() { @Test public void ppMap() { - assertThat(f.filter(ImmutableMap.of("a", "foo", "b", "bar"), null)) - .isEqualTo("{% raw %}(RegularImmutableMap: {a=foo, b=bar}){% endraw %}"); + assertThat(f.filter(ImmutableMap.of("b", "foo", "a", "bar"), null)) + .isEqualTo("{% raw %}(RegularImmutableMap: {a=bar, b=foo}){% endraw %}"); } @Test From 9ac4f6e42fbe9f06c43210aef4d397d09fae5d8f Mon Sep 17 00:00:00 2001 From: Libo Song Date: Wed, 7 Feb 2024 11:26:23 -0500 Subject: [PATCH 2/2] Cannot build on java21 yet. --- .build-jdk17 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .build-jdk17 diff --git a/.build-jdk17 b/.build-jdk17 new file mode 100644 index 000000000..e69de29bb