diff --git a/JSONObject.java b/JSONObject.java index 2f613f855..10faa494f 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -30,11 +30,12 @@ of this software and associated documentation files (the "Software"), to deal import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.math.*; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Collection; import java.util.Enumeration; -import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -131,7 +132,8 @@ public boolean equals(Object object) { * * @return The string "null". */ - public String toString() { + @Override + public String toString() { return "null"; } } @@ -153,7 +155,7 @@ public String toString() { * Construct an empty JSONObject. */ public JSONObject() { - this.map = new HashMap(); + this.map = new LinkedHashMap(); } /** @@ -239,7 +241,7 @@ public JSONObject(JSONTokener x) throws JSONException { * the JSONObject. */ public JSONObject(Map map) { - this.map = new HashMap(); + this.map = new LinkedHashMap(); if (map != null) { for (final Entry e : map.entrySet()) { final Object value = e.getValue(); @@ -717,6 +719,8 @@ public String getString(String key) throws JSONException { if (object instanceof String) { return (String) object; } + // AndrĂ¡s changed this + if (object!=null) return object.toString(); throw new JSONException("JSONObject[" + quote(key) + "] not a string."); } @@ -1579,7 +1583,8 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException { * brace) and ending with } (right * brace). */ - public String toString() { + @Override + public String toString() { try { return this.toString(0); } catch (Exception e) { diff --git a/XMLTokener.java b/XMLTokener.java index e45e747dc..3271c2e29 100644 --- a/XMLTokener.java +++ b/XMLTokener.java @@ -36,10 +36,10 @@ public class XMLTokener extends JSONTokener { /** The table of entity values. It initially contains Character values for * amp, apos, gt, lt, quot. */ - public static final java.util.HashMap entity; + public static final java.util.LinkedHashMap entity; static { - entity = new java.util.HashMap(8); + entity = new java.util.LinkedHashMap(8); entity.put("amp", XML.AMP); entity.put("apos", XML.APOS); entity.put("gt", XML.GT);