Skip to content

Commit e0894c3

Browse files
author
Szabó András
committed
I hate that getString does not return String when toString is available, fixed
1 parent c182e60 commit e0894c3

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

JSONObject.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ of this software and associated documentation files (the "Software"), to deal
3030
import java.lang.reflect.Field;
3131
import java.lang.reflect.Method;
3232
import java.lang.reflect.Modifier;
33-
import java.math.*;
33+
import java.math.BigDecimal;
34+
import java.math.BigInteger;
3435
import java.util.Collection;
3536
import java.util.Enumeration;
36-
import java.util.LinkedHashMap;
3737
import java.util.Iterator;
38+
import java.util.LinkedHashMap;
3839
import java.util.Locale;
3940
import java.util.Map;
4041
import java.util.Map.Entry;
@@ -131,7 +132,8 @@ public boolean equals(Object object) {
131132
*
132133
* @return The string "null".
133134
*/
134-
public String toString() {
135+
@Override
136+
public String toString() {
135137
return "null";
136138
}
137139
}
@@ -717,6 +719,10 @@ public String getString(String key) throws JSONException {
717719
if (object instanceof String) {
718720
return (String) object;
719721
}
722+
// András changed this
723+
if (object instanceof Number) {
724+
return object.toString();
725+
}
720726
throw new JSONException("JSONObject[" + quote(key) + "] not a string.");
721727
}
722728

@@ -1579,7 +1585,8 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
15791585
* brace)</small> and ending with <code>}</code>&nbsp;<small>(right
15801586
* brace)</small>.
15811587
*/
1582-
public String toString() {
1588+
@Override
1589+
public String toString() {
15831590
try {
15841591
return this.toString(0);
15851592
} catch (Exception e) {

0 commit comments

Comments
 (0)