1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

changed all method signatures containing collections and maps to accept

wildcard generic types, e.g. Collection<?> instead of
Collection<Object>. This was proposed by other pull requests (#111,
#112) already. Consider this commit as merge with #111 and #112.

JSONArray:
	- put(Collection<?> value) {...}
	- put(Map<String, ?> value) {...}
	- put(int index, Collection<?> value) throws JSONException {...}
	- put(int index, Map<String, ?> value) throws JSONException {...}

JSONObject:
	- put(String key, Collection<?> value) throws JSONException {...}
	- put(String key, Map<String, ?> value) throws JSONException {...}


Changed all code affected by new JSONObject and JSONArray constructors:
	
JSONObject:
	- valueToString(Object value) throws JSONException {
		- value instanceof Map
		- value instanceof Collection
	  }
	- wrap(Object object) {
		- value instanceof Map
		- value instanceof Collection
	  }
	- writeValue(Writer writer, Object value,
			 int indentFactor, int indent){
        - value instanceof Map
        - value instanceof Collection
      }
This commit is contained in:
Lukas Treyer 2015-10-11 11:20:08 +02:00
parent 0afd26623c
commit 409eb9f292
2 changed files with 13 additions and 14 deletions

View file

@ -1206,7 +1206,7 @@ public class JSONObject {
* @return this.
* @throws JSONException
*/
public JSONObject put(String key, Collection<Object> value) throws JSONException {
public JSONObject put(String key, Collection<?> value) throws JSONException {
this.put(key, new JSONArray(value));
return this;
}
@ -1270,7 +1270,7 @@ public class JSONObject {
* @return this.
* @throws JSONException
*/
public JSONObject put(String key, Map<String, Object> value) throws JSONException {
public JSONObject put(String key, Map<String, ?> value) throws JSONException {
this.put(key, new JSONObject(value));
return this;
}
@ -1666,12 +1666,12 @@ public class JSONObject {
}
if (value instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) value;
Map<String, ?> map = (Map<String, ?>) value;
return new JSONObject(map).toString();
}
if (value instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) value;
Collection<?> coll = (Collection<?>) value;
return new JSONArray(coll).toString();
}
if (value.getClass().isArray()) {
@ -1710,7 +1710,7 @@ public class JSONObject {
if (object instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) object;
Collection<?> coll = (Collection<?>) object;
return new JSONArray(coll);
}
if (object.getClass().isArray()) {
@ -1718,7 +1718,7 @@ public class JSONObject {
}
if (object instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) object;
Map<String, ?> map = (Map<String, ?>) object;
return new JSONObject(map);
}
Package objectPackage = object.getClass().getPackage();
@ -1758,13 +1758,12 @@ public class JSONObject {
((JSONArray) value).write(writer, indentFactor, indent);
} else if (value instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) value;
Map<String, ?> map = (Map<String, ?>) value;
new JSONObject(map).write(writer, indentFactor, indent);
} else if (value instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) value;
new JSONArray(coll).write(writer, indentFactor,
indent);
Collection<?> coll = (Collection<?>) value;
new JSONArray(coll).write(writer, indentFactor, indent);
} else if (value.getClass().isArray()) {
new JSONArray(value).write(writer, indentFactor, indent);
} else if (value instanceof Number) {