Build json string in order of entry appearance

pull/55/head
Richard Körber 2017-08-17 22:39:30 +02:00
parent f434fd70b4
commit b708b2f199
2 changed files with 6 additions and 6 deletions

View File

@ -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<String, Object> data = new TreeMap<>();
private final Map<String, Object> data = new LinkedHashMap<>();
/**
* Puts a property. If a property with the key exists, it will be replaced.

View File

@ -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<String, Object> 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}"));
}
/**