From b708b2f199fef8a561794ea321f3b1c9b926e552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Thu, 17 Aug 2017 22:39:30 +0200 Subject: [PATCH] Build json string in order of entry appearance --- .../main/java/org/shredzone/acme4j/util/JSONBuilder.java | 4 ++-- .../java/org/shredzone/acme4j/util/JSONBuilderTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/util/JSONBuilder.java b/acme4j-client/src/main/java/org/shredzone/acme4j/util/JSONBuilder.java index d3544e52..d8cdab69 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/util/JSONBuilder.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/util/JSONBuilder.java @@ -20,9 +20,9 @@ import java.security.PublicKey; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; -import java.util.TreeMap; import org.jose4j.json.JsonUtil; import org.jose4j.jwk.JsonWebKey; @@ -43,7 +43,7 @@ import org.shredzone.acme4j.exception.AcmeProtocolException; */ public class JSONBuilder { - private final Map data = new TreeMap<>(); + private final Map data = new LinkedHashMap<>(); /** * Puts a property. If a property with the key exists, it will be replaced. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/util/JSONBuilderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/util/JSONBuilderTest.java index 46fe6670..49f7ba76 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/util/JSONBuilderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/util/JSONBuilderTest.java @@ -43,8 +43,8 @@ public class JSONBuilderTest { } /** - * Test basic data types. Also test that methods return {@code this}, that existing - * keys are replaced, and that the output keys are in lexicographical order. + * Test basic data types. Also test that methods return {@code this}, and that + * existing keys are replaced. */ @Test public void testBasics() { @@ -60,7 +60,7 @@ public class JSONBuilderTest { res = cb.put("fooInt", 456); assertThat(res, is(sameInstance(cb))); - assertThat(cb.toString(), is("{\"fooInt\":456,\"fooStr\":\"String\"}")); + assertThat(cb.toString(), is("{\"fooStr\":\"String\",\"fooInt\":456}")); Map map = cb.toMap(); assertThat(map.keySet(), hasSize(2)); @@ -142,7 +142,7 @@ public class JSONBuilderTest { cb.put("foo", 123); sub.put("foo", 456); - assertThat(cb.toString(), is("{\"foo\":123,\"sub\":{\"foo\":456}}")); + assertThat(cb.toString(), is("{\"sub\":{\"foo\":456},\"foo\":123}")); } /**