summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-01-10 11:17:43 +0000
committerNarayan Kamath <narayan@google.com>2014-01-13 10:37:56 +0000
commit319bef83054979209a01b484af34ce1087d28559 (patch)
tree9e0fdecdd8a5778e5f408df97c0268416539a29c
parentd1e95700f052dc5197ce807447d1f2bd8ac11aa7 (diff)
downloadlibcore-319bef83054979209a01b484af34ce1087d28559.zip
libcore-319bef83054979209a01b484af34ce1087d28559.tar.gz
libcore-319bef83054979209a01b484af34ce1087d28559.tar.bz2
Fix JSONObject#test_toString_listAsMapValues
Changed the map type in JSONObject to a LinkedHashMap so that its iteration order is well defined. bug: 12476022 Change-Id: I8f2e40fd6bca5f776396aba4c9fde6e9d58f662e
-rw-r--r--json/src/main/java/org/json/JSONObject.java6
-rw-r--r--json/src/test/java/org/json/JSONObjectTest.java5
2 files changed, 6 insertions, 5 deletions
diff --git a/json/src/main/java/org/json/JSONObject.java b/json/src/main/java/org/json/JSONObject.java
index 5e73327..1f474b8 100644
--- a/json/src/main/java/org/json/JSONObject.java
+++ b/json/src/main/java/org/json/JSONObject.java
@@ -18,8 +18,8 @@ package org.json;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
// Note: this class was written without inspecting the non-free org.json sourcecode.
@@ -104,13 +104,13 @@ public class JSONObject {
}
};
- private final Map<String, Object> nameValuePairs;
+ private final LinkedHashMap<String, Object> nameValuePairs;
/**
* Creates a {@code JSONObject} with no name/value mappings.
*/
public JSONObject() {
- nameValuePairs = new HashMap<String, Object>();
+ nameValuePairs = new LinkedHashMap<String, Object>();
}
/**
diff --git a/json/src/test/java/org/json/JSONObjectTest.java b/json/src/test/java/org/json/JSONObjectTest.java
index 8abd88f..d0a1d2e 100644
--- a/json/src/test/java/org/json/JSONObjectTest.java
+++ b/json/src/test/java/org/json/JSONObjectTest.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.TreeMap;
import junit.framework.TestCase;
/**
@@ -988,9 +989,9 @@ public class JSONObjectTest extends TestCase {
ArrayList<Object> list = new ArrayList<Object>();
list.add("a");
list.add(new ArrayList<String>());
- HashMap<String, Object> map = new HashMap<String, Object>();
+ Map<String, Object> map = new TreeMap<String, Object>();
map.put("x", "l");
map.put("y", list);
- assertEquals("{\"y\":[\"a\",[]],\"x\":\"l\"}", new JSONObject(map).toString());
+ assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
}
}