Skip to content

Commit 1968fef

Browse files
author
Robert Miyashiro
committed
Maintaining field order
1 parent 3e48955 commit 1968fef

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Taken from the reference implementation found at http://www.JSON.org
66
# Changes
77

88
- Restructured into a deployable module (based on https://github.com/eskatos/org.json-java)
9-
9+
- Fields now retain their ordering

orgjson/src/main/java/org/json/JSONObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
3232
import java.lang.reflect.Modifier;
3333
import java.util.Collection;
3434
import java.util.Enumeration;
35-
import java.util.HashMap;
35+
import java.util.LinkedHashMap;
3636
import java.util.Iterator;
3737
import java.util.Locale;
3838
import java.util.Map;
@@ -152,7 +152,7 @@ public String toString() {
152152
* Construct an empty JSONObject.
153153
*/
154154
public JSONObject() {
155-
this.map = new HashMap<String, Object>();
155+
this.map = new LinkedHashMap<String, Object>();
156156
}
157157

158158
/**
@@ -243,7 +243,7 @@ public JSONObject(JSONTokener x) throws JSONException {
243243
* @throws JSONException
244244
*/
245245
public JSONObject(Map<String, Object> map) {
246-
this.map = new HashMap<String, Object>();
246+
this.map = new LinkedHashMap<String, Object>();
247247
if (map != null) {
248248
Iterator<Entry<String, Object>> i = map.entrySet().iterator();
249249
while (i.hasNext()) {

0 commit comments

Comments
 (0)