Skip to content

Commit 0cf7491

Browse files
committedMay 6, 2015
Merge pull request #122 from douglascrockford/merge-branch-for-issue-110
Merge branch for issue #110
2 parents b56fe9f + a851bf0 commit 0cf7491

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed
 

‎JSONObject.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ of this software and associated documentation files (the "Software"), to deal
9191
* </ul>
9292
*
9393
* @author JSON.org
94-
* @version 2014-05-03
94+
* @version 2015-05-05
9595
*/
9696
public class JSONObject {
9797
/**
@@ -298,7 +298,7 @@ public JSONObject(Object bean) {
298298
*/
299299
public JSONObject(Object object, String names[]) {
300300
this();
301-
Class c = object.getClass();
301+
Class<?> c = object.getClass();
302302
for (int i = 0; i < names.length; i += 1) {
303303
String name = names[i];
304304
try {
@@ -631,7 +631,7 @@ public static String[] getNames(Object object) {
631631
if (object == null) {
632632
return null;
633633
}
634-
Class klass = object.getClass();
634+
Class<?> klass = object.getClass();
635635
Field[] fields = klass.getFields();
636636
int length = fields.length;
637637
if (length == 0) {
@@ -981,7 +981,7 @@ public String optString(String key, String defaultValue) {
981981
}
982982

983983
private void populateMap(Object bean) {
984-
Class klass = bean.getClass();
984+
Class<?> klass = bean.getClass();
985985

986986
// If klass is a System class then set includeSuperClass to false.
987987

@@ -1512,10 +1512,14 @@ public static String valueToString(Object value) throws JSONException {
15121512
return value.toString();
15131513
}
15141514
if (value instanceof Map) {
1515-
return new JSONObject((Map<String, Object>)value).toString();
1515+
@SuppressWarnings("unchecked")
1516+
Map<String, Object> map = (Map<String, Object>) value;
1517+
return new JSONObject(map).toString();
15161518
}
15171519
if (value instanceof Collection) {
1518-
return new JSONArray((Collection<Object>) value).toString();
1520+
@SuppressWarnings("unchecked")
1521+
Collection<Object> coll = (Collection<Object>) value;
1522+
return new JSONArray(coll).toString();
15191523
}
15201524
if (value.getClass().isArray()) {
15211525
return new JSONArray(value).toString();
@@ -1551,13 +1555,17 @@ public static Object wrap(Object object) {
15511555
}
15521556

15531557
if (object instanceof Collection) {
1554-
return new JSONArray((Collection<Object>) object);
1558+
@SuppressWarnings("unchecked")
1559+
Collection<Object> coll = (Collection<Object>) object;
1560+
return new JSONArray(coll);
15551561
}
15561562
if (object.getClass().isArray()) {
15571563
return new JSONArray(object);
15581564
}
15591565
if (object instanceof Map) {
1560-
return new JSONObject((Map<String, Object>) object);
1566+
@SuppressWarnings("unchecked")
1567+
Map<String, Object> map = (Map<String, Object>) object;
1568+
return new JSONObject(map);
15611569
}
15621570
Package objectPackage = object.getClass().getPackage();
15631571
String objectPackageName = objectPackage != null ? objectPackage
@@ -1595,9 +1603,13 @@ static final Writer writeValue(Writer writer, Object value,
15951603
} else if (value instanceof JSONArray) {
15961604
((JSONArray) value).write(writer, indentFactor, indent);
15971605
} else if (value instanceof Map) {
1598-
new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent);
1606+
@SuppressWarnings("unchecked")
1607+
Map<String, Object> map = (Map<String, Object>) value;
1608+
new JSONObject(map).write(writer, indentFactor, indent);
15991609
} else if (value instanceof Collection) {
1600-
new JSONArray((Collection<Object>) value).write(writer, indentFactor,
1610+
@SuppressWarnings("unchecked")
1611+
Collection<Object> coll = (Collection<Object>) value;
1612+
new JSONArray(coll).write(writer, indentFactor,
16011613
indent);
16021614
} else if (value.getClass().isArray()) {
16031615
new JSONArray(value).write(writer, indentFactor, indent);

‎Property.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
3131
/**
3232
* Converts a Property file data into JSONObject and back.
3333
* @author JSON.org
34-
* @version 2014-05-03
34+
* @version 2015-05-05
3535
*/
3636
public class Property {
3737
/**
@@ -43,7 +43,7 @@ public class Property {
4343
public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException {
4444
JSONObject jo = new JSONObject();
4545
if (properties != null && !properties.isEmpty()) {
46-
Enumeration enumProperties = properties.propertyNames();
46+
Enumeration<?> enumProperties = properties.propertyNames();
4747
while(enumProperties.hasMoreElements()) {
4848
String name = (String)enumProperties.nextElement();
4949
jo.put(name, properties.getProperty(name));

0 commit comments

Comments
 (0)